feat: add versioned migrations and kysely query layer

This commit is contained in:
Bastian Wagner
2026-08-17 14:33:28 +02:00
parent acfbb3ab22
commit ec95a8e527
17 changed files with 513 additions and 50 deletions

View 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');
};