feat: add versioned migrations and kysely query layer
This commit is contained in:
25
backend/migrations/1700000005000_create-trip-members.cjs
Normal file
25
backend/migrations/1700000005000_create-trip-members.cjs
Normal file
@@ -0,0 +1,25 @@
|
||||
exports.up = (pgm) => {
|
||||
pgm.createTable('trip_members', {
|
||||
id: { type: 'uuid', primaryKey: true, default: pgm.func('gen_random_uuid()') },
|
||||
trip_id: { type: 'uuid', notNull: true, references: 'trips(id)', onDelete: 'CASCADE' },
|
||||
user_id: { type: 'uuid', notNull: true, references: 'users(id)' },
|
||||
role: { type: 'text', notNull: true },
|
||||
status: { type: 'text', notNull: true },
|
||||
joined_at: { type: 'timestamptz' },
|
||||
created_at: { type: 'timestamptz', notNull: true, default: pgm.func('now()') },
|
||||
updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('now()') },
|
||||
});
|
||||
pgm.addConstraint('trip_members', 'trip_members_trip_user_key', 'UNIQUE(trip_id, user_id)');
|
||||
pgm.addConstraint('trip_members', 'trip_members_role_check', "CHECK (role IN ('OWNER','MEMBER'))");
|
||||
pgm.addConstraint(
|
||||
'trip_members',
|
||||
'trip_members_status_check',
|
||||
"CHECK (status IN ('INVITED','ACTIVE','DECLINED'))",
|
||||
);
|
||||
pgm.createIndex('trip_members', 'trip_id');
|
||||
pgm.createIndex('trip_members', 'user_id');
|
||||
};
|
||||
|
||||
exports.down = (pgm) => {
|
||||
pgm.dropTable('trip_members');
|
||||
};
|
||||
Reference in New Issue
Block a user