Thanks the same!
Actually, I think right now that what we practically need is a way to force drop and wipe a database regardless of what it feels about it, if possible.
I have tried to get you the information needed, and we’ll see if it is enough.
We use node.js and Sequelize and the following files are used to define the relationship that borked the database;
‘use strict’
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable(‘files’, {
id: {
type: Sequelize.STRING,
primaryKey: true,
allowNull: false,
defaultValue: Sequelize.UUIDV4,
},
url: {
type: Sequelize.STRING(1024),
allowNull: false,
},
file_path: {
type: Sequelize.STRING(1024),
allowNull: false,
},
is_public: {
type: Sequelize.BOOLEAN,
defaultValue: true,
},
created_at: {
type: Sequelize.DATE(6),
defaultValue: Sequelize.literal(‘CURRENT_TIMESTAMP’),
},
updated_at: {
type: Sequelize.DATE(6),
defaultValue: Sequelize.literal(‘CURRENT_TIMESTAMP’),
onUpdate: Sequelize.literal(‘CURRENT_TIMESTAMP’),
},
})
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable(‘files’)
},
}
‘use strict’
module.exports = {
up: (queryInterface, Sequelize) => {
return Promise.all([
queryInterface.createTable(‘users’, {
id: {
type: Sequelize.STRING,
primaryKey: true,
allowNull: false,
defaultValue: Sequelize.UUIDV4,
},
username: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
user_search: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
email: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
avatar_id: {
type: Sequelize.STRING,
references: {
model: ‘files’,
key: ‘id’,
},
onUpdate: ‘CASCADE’,
onDelete: ‘SET NULL’,
},
cover_id: {
type: Sequelize.STRING,
references: {
model: ‘files’,
key: ‘id’,
},
onUpdate: ‘CASCADE’,
onDelete: ‘SET NULL’,
},
bio: {
type: Sequelize.STRING(2048),
},
notifications_token: {
type: Sequelize.STRING,
},
metadata: {
type: Sequelize.JSON,
},
created_at: {
type: Sequelize.DATE(6),
defaultValue: Sequelize.literal(‘CURRENT_TIMESTAMP’),
},
updated_at: {
type: Sequelize.DATE(6),
defaultValue: Sequelize.literal(‘CURRENT_TIMESTAMP’),
onUpdate: Sequelize.literal(‘CURRENT_TIMESTAMP’),
},
}),
])
},
down: (queryInterface, Sequelize) => {
return Promise.all([
queryInterface.dropTable(‘users’),
])
},
}
‘use strict’
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn(‘files’, ‘user_id’, Sequelize.STRING, {
after: ‘id’,
})
await queryInterface.addConstraint('files', ['user_id'], {
type: 'foreign key',
name: 'user_files',
references: {
table: 'users',
field: 'id',
},
onDelete: 'cascade',
onUpdate: 'cascade',
})
return true
},
down: async (queryInterface, Sequelize) => {
await queryInterface.removeConstraint(‘files’, ‘user_files’)
await queryInterface.removeColumn(‘files’, ‘user_id’)
return true
},
}
The issue was that at the beginning this was not there
await queryInterface.removeConstraint(‘files’, ‘user_files’)
await queryInterface.removeColumn(‘files’, ‘user_id’)
4:04 PM
I guess this is the constraint making it hard to remove
await queryInterface.addConstraint(‘files’, [‘user_id’], {
type: ‘foreign key’,
name: ‘user_files’,
references: {
table: ‘users’,
field: ‘id’,
},
onDelete: ‘cascade’,
onUpdate: ‘cascade’,
})
Cheers,
PS