Autosave: 20260314-143316
This commit is contained in:
parent
1d4afc6f1e
commit
4eff053ea7
31
backend/src/db/migrations/1773497460361-create-files.js
Normal file
31
backend/src/db/migrations/1773497460361-create-files.js
Normal file
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.createTable('files', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
type: Sequelize.UUID,
|
||||
defaultValue: Sequelize.UUIDV4
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
url: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.dropTable('files');
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.addColumn('files', 'belongsTo', {
|
||||
type: Sequelize.STRING(255),
|
||||
allowNull: true,
|
||||
});
|
||||
await queryInterface.addColumn('files', 'belongsToId', {
|
||||
type: Sequelize.UUID,
|
||||
allowNull: true,
|
||||
});
|
||||
await queryInterface.addColumn('files', 'belongsToColumn', {
|
||||
type: Sequelize.STRING(255),
|
||||
allowNull: true,
|
||||
});
|
||||
},
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.removeColumn('files', 'belongsTo');
|
||||
await queryInterface.removeColumn('files', 'belongsToId');
|
||||
await queryInterface.removeColumn('files', 'belongsToColumn');
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.addColumn('files', 'sizeInBytes', {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: true,
|
||||
});
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.removeColumn('files', 'sizeInBytes');
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
return queryInterface.addColumn('files', 'privateUrl', {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
});
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
return queryInterface.removeColumn('files', 'privateUrl');
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,18 @@
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
const tableInfo = await queryInterface.describeTable('files');
|
||||
if (!tableInfo.publicUrl) {
|
||||
await queryInterface.addColumn('files', 'publicUrl', {
|
||||
type: Sequelize.STRING(2083),
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
});
|
||||
}
|
||||
},
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
const tableInfo = await queryInterface.describeTable('files');
|
||||
if (tableInfo.publicUrl) {
|
||||
await queryInterface.removeColumn('files', 'publicUrl');
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
const tableInfo = await queryInterface.describeTable('files');
|
||||
if (!tableInfo.deletedAt) {
|
||||
await queryInterface.addColumn('files', 'deletedAt', {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.removeColumn('files', 'deletedAt');
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
const tableInfo = await queryInterface.describeTable('files');
|
||||
if (!tableInfo.createdById) {
|
||||
await queryInterface.addColumn('files', 'createdById', {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: 'users',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'SET NULL'
|
||||
});
|
||||
}
|
||||
},
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.removeColumn('files', 'createdById');
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user