1614678016791-add_user_settings.ts 1.2 KB

1234567891011121314151617181920
  1. import { MigrationInterface, QueryRunner } from 'typeorm'
  2. export class AddUserSettings1614678016791 implements MigrationInterface {
  3. name = 'AddUserSettings1614678016791'
  4. public async up(queryRunner: QueryRunner): Promise<void> {
  5. await queryRunner.query(
  6. 'CREATE TABLE `settings` (`uuid` varchar(36) NOT NULL, `name` varchar(255) NOT NULL, `value` varchar(255) NOT NULL, `encrypted` tinyint(1) NOT NULL DEFAULT 0, `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `user_uuid` varchar(36) NOT NULL, INDEX `index_settings_on_name_and_user_uuid` (`name`, `user_uuid`), PRIMARY KEY (`uuid`)) ENGINE=InnoDB',
  7. )
  8. await queryRunner.query(
  9. 'ALTER TABLE `settings` ADD CONSTRAINT `FK_1cc1d030b83d6030795d3e7e63f` FOREIGN KEY (`user_uuid`) REFERENCES `users`(`uuid`) ON DELETE CASCADE ON UPDATE NO ACTION',
  10. )
  11. }
  12. public async down(queryRunner: QueryRunner): Promise<void> {
  13. await queryRunner.query('ALTER TABLE `settings` DROP FOREIGN KEY `FK_1cc1d030b83d6030795d3e7e63f`')
  14. await queryRunner.query('DROP INDEX `index_settings_on_name_and_user_uuid` ON `settings`')
  15. await queryRunner.query('DROP TABLE `settings`')
  16. }
  17. }