feat: add versioned migrations and kysely query layer
This commit is contained in:
26
backend/migrations/1700000003000_create-trips.cjs
Normal file
26
backend/migrations/1700000003000_create-trips.cjs
Normal file
@@ -0,0 +1,26 @@
|
||||
exports.up = (pgm) => {
|
||||
pgm.createTable('trips', {
|
||||
id: { type: 'uuid', primaryKey: true, default: pgm.func('gen_random_uuid()') },
|
||||
name: { type: 'text', notNull: true },
|
||||
description: { type: 'text' },
|
||||
owner_id: { type: 'uuid', notNull: true, references: 'users(id)' },
|
||||
start_date: { type: 'date' },
|
||||
end_date: { type: 'date' },
|
||||
status: { type: 'text', notNull: true, default: 'DRAFT' },
|
||||
planning_stage: { type: 'text' },
|
||||
currency: { type: 'text', notNull: true, default: 'EUR' },
|
||||
version: { type: 'integer', notNull: true, default: 1 },
|
||||
created_at: { type: 'timestamptz', notNull: true, default: pgm.func('now()') },
|
||||
updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('now()') },
|
||||
});
|
||||
pgm.addConstraint(
|
||||
'trips',
|
||||
'trips_status_check',
|
||||
"CHECK (status IN ('DRAFT','PLANNING','BOOKING','UPCOMING','ACTIVE','COMPLETED','ARCHIVED'))",
|
||||
);
|
||||
pgm.createIndex('trips', 'owner_id');
|
||||
};
|
||||
|
||||
exports.down = (pgm) => {
|
||||
pgm.dropTable('trips');
|
||||
};
|
||||
Reference in New Issue
Block a user