9 lines
1.0 KiB
TypeScript
9 lines
1.0 KiB
TypeScript
import type { Sequelize } from "sequelize";
|
|
import { DataTypes, QueryTypes } from "sequelize";
|
|
export async function migratePersonPhotos(database: Sequelize): Promise<void> {
|
|
const rows = await database.query<{ name: string }>("SELECT TABLE_NAME AS name FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE()", { type: QueryTypes.SELECT });
|
|
if (rows.some((row) => row.name === "person_photos")) return;
|
|
await database.getQueryInterface().createTable("person_photos", { personId: { type: DataTypes.UUID, primaryKey: true }, companyId: { type: DataTypes.UUID, allowNull: false }, data: { type: DataTypes.BLOB("medium"), allowNull: false }, version: { type: DataTypes.STRING(64), allowNull: false }, createdAt: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW }, updatedAt: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW } });
|
|
await database.query("ALTER TABLE person_photos ADD CONSTRAINT person_photos_person_fk FOREIGN KEY (personId, companyId) REFERENCES company_contacts (id, companyId) ON DELETE CASCADE");
|
|
}
|