split FKs into another file

This commit is contained in:
counterweight 2025-03-10 13:43:55 +01:00
parent 3b2edb4ca9
commit 317ca7ded2
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 74 additions and 38 deletions

View file

@ -10,6 +10,7 @@ module.exports = {
database: process.env.POSTGRES_DB,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
logging: console.log,
define: {
timestamps: false,
freezeTableName: true,

View file

@ -48,7 +48,7 @@ module.exports = {
{ transaction: t }
),
queryInterface.createTable(
'login_challenge_completed',
'nostr_challenge_created',
{
uuid: {
type: Sequelize.UUID,
@ -56,13 +56,14 @@ module.exports = {
unique: true,
primaryKey: true,
},
nostr_challenge_completed_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
public_key: {
challenge: {
type: Sequelize.STRING,
allowNull: false,
unique: true,
},
expires_at: {
type: Sequelize.DATE,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
@ -91,32 +92,6 @@ module.exports = {
},
{ transaction: t }
),
queryInterface.createTable(
'nostr_challenge_created',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
challenge: {
type: Sequelize.STRING,
allowNull: false,
unique: true,
},
expires_at: {
type: Sequelize.DATE,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'nostr_challenge_completed',
{
@ -130,12 +105,6 @@ module.exports = {
type: Sequelize.STRING,
allowNull: false,
unique: true,
references: {
model: {
tableName: 'nostr_challenge_created',
},
key: 'challenge',
},
},
signed_event: {
type: Sequelize.JSONB,
@ -152,6 +121,30 @@ module.exports = {
},
{ transaction: t }
),
queryInterface.createTable(
'login_challenge_completed',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
nostr_challenge_completed_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
public_key: {
type: Sequelize.STRING,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
]);
});
},

View file

@ -0,0 +1,42 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.addConstraint('login_challenge_created', {
fields: ['nostr_challenge_uuid'],
type: 'foreign key',
references: {
table: 'nostr_challenge_created',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
}),
queryInterface.addConstraint('nostr_challenge_completed', {
fields: ['challenge'],
type: 'foreign key',
references: {
table: 'nostr_challenge_created',
field: 'challenge',
},
onDelete: 'cascade',
onUpdate: 'cascade',
}),
queryInterface.addConstraint('login_challenge_completed', {
fields: ['nostr_challenge_completed_uuid'],
type: 'foreign key',
references: {
table: 'nostr_challenge_completed',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
}),
]);
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Users');
},
};