Browse Source

fix(migration): populate field before adding NOT NULL constraint

Nicolas Meienberger 2 years ago
parent
commit
8b69250bfa

+ 1 - 1
packages/dashboard/src/components/AppTile/index.tsx

@@ -7,7 +7,7 @@ import AppLogo from '../AppLogo/AppLogo';
 import { limitText } from '../../modules/AppStore/helpers/table.helpers';
 import { AppInfo, AppStatusEnum } from '../../generated/graphql';
 
-type AppTileInfo = Pick<AppInfo, 'id' | 'name' | 'description' | 'image' | 'short_desc'>;
+type AppTileInfo = Pick<AppInfo, 'id' | 'name' | 'description' | 'short_desc'>;
 
 const AppTile: React.FC<{ app: AppTileInfo; status: AppStatusEnum }> = ({ app, status }) => {
   const bg = useColorModeValue('white', '#1a202c');

+ 0 - 1
packages/dashboard/src/modules/AppStore/components/AppStoreTile.tsx

@@ -10,7 +10,6 @@ type App = {
   name: string;
   categories: string[];
   short_desc: string;
-  image: string;
 };
 
 const AppStoreTile: React.FC<{ app: App }> = ({ app }) => {

+ 0 - 1
packages/dashboard/src/modules/AppStore/components/FeaturedCard.tsx

@@ -21,7 +21,6 @@ const FeaturedCard: React.FC<IProps> = ({ app, show }) => {
       >
         <div className="relative flex flex-1 w-max lg:bg-gradient-to-r from-white via-white">
           <div className="flex absolute bottom-0 flex-row p-3">
-            <img src={app.image} width={80} height={80} className="rounded-lg mr-2" />
             <div className="self-end mb-1">
               <div className="font-bold text-xl">{app.name}</div>
               <div className="text-md">{app.short_desc}</div>

+ 14 - 10
packages/system-api/src/config/migrations/1659645508713-AppVersion.ts

@@ -1,16 +1,20 @@
-import { MigrationInterface, QueryRunner } from "typeorm";
+import { MigrationInterface, QueryRunner } from 'typeorm';
 
 export class AppVersion1659645508713 implements MigrationInterface {
-    name = 'AppVersion1659645508713'
+  name = 'AppVersion1659645508713';
 
-    public async up(queryRunner: QueryRunner): Promise<void> {
-        await queryRunner.query(`ALTER TABLE "app" ADD "version" integer NOT NULL DEFAULT '0'`);
-        await queryRunner.query(`ALTER TABLE "app" ADD CONSTRAINT "UQ_9478629fc093d229df09e560aea" UNIQUE ("id")`);
-    }
+  public async up(queryRunner: QueryRunner): Promise<void> {
+    await queryRunner.query(`ALTER TABLE "app" ADD "version" integer DEFAULT '0'`);
+    // populate all apps with a version
+    await queryRunner.query(`UPDATE "app" SET "version" = '1'`);
+    // add NOT NULL constraint
+    await queryRunner.query(`ALTER TABLE "app" ALTER COLUMN "version" SET NOT NULL`);
 
-    public async down(queryRunner: QueryRunner): Promise<void> {
-        await queryRunner.query(`ALTER TABLE "app" DROP CONSTRAINT "UQ_9478629fc093d229df09e560aea"`);
-        await queryRunner.query(`ALTER TABLE "app" DROP COLUMN "version"`);
-    }
+    await queryRunner.query(`ALTER TABLE "app" ADD CONSTRAINT "UQ_9478629fc093d229df09e560aea" UNIQUE ("id")`);
+  }
 
+  public async down(queryRunner: QueryRunner): Promise<void> {
+    await queryRunner.query(`ALTER TABLE "app" DROP CONSTRAINT "UQ_9478629fc093d229df09e560aea"`);
+    await queryRunner.query(`ALTER TABLE "app" DROP COLUMN "version"`);
+  }
 }

+ 0 - 2
packages/system-api/src/core/updates/run.ts

@@ -1,8 +1,6 @@
 import { updateV040 } from './v040';
-import { updateV050 } from './v050';
 
 export const runUpdates = async (): Promise<void> => {
   // v040: Update to 0.4.0
   await updateV040();
-  // await updateV050();
 };

+ 0 - 29
packages/system-api/src/core/updates/v050.ts

@@ -1,29 +0,0 @@
-import logger from '../../config/logger/logger';
-import App from '../../modules/apps/app.entity';
-import Update, { UpdateStatusEnum } from '../../modules/system/update.entity';
-
-const UPDATE_NAME = 'v050';
-
-export const updateV050 = async (): Promise<void> => {
-  try {
-    const update = await Update.findOne({ where: { name: UPDATE_NAME } });
-
-    if (update) {
-      logger.info(`Update ${UPDATE_NAME} already applied`);
-      return;
-    }
-
-    const apps = await App.find();
-
-    for (const app of apps) {
-      await App.update(app.id, { version: 1 });
-    }
-
-    await Update.create({ name: UPDATE_NAME, status: UpdateStatusEnum.SUCCESS }).save();
-    logger.info(`Update ${UPDATE_NAME} applied`);
-  } catch (error) {
-    logger.error(error);
-    console.error(error);
-    await Update.create({ name: UPDATE_NAME, status: UpdateStatusEnum.FAILED }).save();
-  }
-};