chore: Remove long deprecated database columns (#3821)

* chore: Remove long deprecated database columns

* test

* Update 20220720221531-remove-deprecated-columns.js

* fix rollback

* Add guard for upgrading past v0.54.0
This commit is contained in:
Tom Moor
2022-08-25 19:52:01 +01:00
committed by GitHub
parent a869ab7609
commit 864f585e5b
3 changed files with 61 additions and 12 deletions

View File

@@ -0,0 +1,61 @@
'use strict';
module.exports = {
async up(queryInterface) {
await queryInterface.sequelize.transaction(async (transaction) => {
// This guard prevents the migration from running and destroying this
// service data if the script from v0.54.0 has not yet been run.
if (process.env.DEPLOYMENT !== "hosted") {
const [teams] = await queryInterface.sequelize.query(
`SELECT COUNT(*) FROM teams`,
{ transaction }
);
const [authenticationProviders] = await queryInterface.sequelize.query(
`SELECT COUNT(*) FROM authentication_providers`,
{ transaction }
);
if (teams[0].count > 0 && authenticationProviders[0].count === 0) {
throw Error("Refusing to destroy deprecated columns without authentication providers");
}
}
await queryInterface.removeColumn("attachments", "url", { transaction });
await queryInterface.removeColumn("users", "service", { transaction });
await queryInterface.removeColumn("users", "serviceId", { transaction });
await queryInterface.removeColumn("teams", "slackId", { transaction });
await queryInterface.removeColumn("teams", "googleId", { transaction });
});
},
async down(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.addColumn("attachments", "url", {
type: Sequelize.STRING(4096),
allowNull: false,
defaultValue: "",
transaction
});
await queryInterface.addColumn("users", "service", {
type: Sequelize.STRING,
allowNull: true,
transaction
});
await queryInterface.addColumn("users", "serviceId", {
type: Sequelize.STRING,
allowNull: true,
transaction
});
await queryInterface.addColumn("teams", "slackId", {
type: Sequelize.STRING,
allowNull: true,
transaction
});
await queryInterface.addColumn("teams", "googleId", {
type: Sequelize.STRING,
allowNull: true,
transaction
});
});
}
};

View File

@@ -28,13 +28,6 @@ class Attachment extends IdModel {
@Column
key: string;
@Length({
max: 4096,
msg: "url must be 4096 characters or less",
})
@Column
url: string;
@Length({
max: 255,
msg: "contentType must be 255 characters or less",
@@ -69,10 +62,6 @@ class Attachment extends IdModel {
return getFileByKey(this.key);
}
/**
* Use this instead of url which will be deleted soon, the column is unneccessary
* and was not updated with the migraiton to the new s3 bucket.
*/
get canonicalUrl() {
return `${publicS3Endpoint()}/${this.key}`;
}

View File

@@ -377,7 +377,6 @@ export async function buildAttachment(overrides: Partial<Attachment> = {}) {
count++;
return Attachment.create({
key: `uploads/key/to/file ${count}.png`,
url: `https://redirect.url.com/uploads/key/to/file${count}.png`,
contentType: "image/png",
size: 100,
acl: "public-read",