소스 검색

fix: migrations

Nicolas Meienberger 2 년 전
부모
커밋
09f7dcefc9

+ 2 - 3
packages/system-api/ormconfig.ts

@@ -6,9 +6,8 @@ export const connectionSource = new DataSource({
   port: 5432,
   port: 5432,
   username: 'tipi',
   username: 'tipi',
   password: 'postgres',
   password: 'postgres',
-  database: 'postgres',
+  database: 'tipi',
   logging: true,
   logging: true,
   synchronize: false,
   synchronize: false,
-  entities: ['/src/modules/**/*.entity.ts'],
-  migrations: ['/src/config/migrations/*.ts'],
+  entities: ['src/modules/**/*.entity.ts'],
 });
 });

+ 1 - 1
packages/system-api/src/config/datasource.ts

@@ -20,7 +20,7 @@ export default new DataSource({
   password: POSTGRES_PASSWORD,
   password: POSTGRES_PASSWORD,
   port: 5432,
   port: 5432,
   logging: !__prod__,
   logging: !__prod__,
-  synchronize: !__prod__,
+  synchronize: false,
   entities: [App, User, Update],
   entities: [App, User, Update],
   migrations: [process.cwd() + '/dist/config/migrations/*.js'],
   migrations: [process.cwd() + '/dist/config/migrations/*.js'],
 });
 });

+ 16 - 0
packages/system-api/src/config/migrations/1659645508713-AppVersion.ts

@@ -0,0 +1,16 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class AppVersion1659645508713 implements MigrationInterface {
+    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 down(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`ALTER TABLE "app" DROP CONSTRAINT "UQ_9478629fc093d229df09e560aea"`);
+        await queryRunner.query(`ALTER TABLE "app" DROP COLUMN "version"`);
+    }
+
+}

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

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

+ 1 - 1
packages/system-api/src/modules/apps/app.entity.ts

@@ -44,7 +44,7 @@ class App extends BaseEntity {
   updatedAt!: Date;
   updatedAt!: Date;
 
 
   @Field(() => AppInfo)
   @Field(() => AppInfo)
-  info(): Promise<AppInfo> {
+  info(): AppInfo {
     return getAppInfo(this.id);
     return getAppInfo(this.id);
   }
   }
 }
 }

+ 1 - 1
packages/system-api/src/modules/apps/apps.helpers.ts

@@ -128,7 +128,7 @@ export const getAvailableApps = async (): Promise<string[]> => {
   return apps;
   return apps;
 };
 };
 
 
-export const getAppInfo = async (id: string): Promise<AppInfo> => {
+export const getAppInfo = (id: string): AppInfo => {
   try {
   try {
     const repoId = config.APPS_REPO_ID;
     const repoId = config.APPS_REPO_ID;
     if (fileExists(`/repos/${repoId}`)) {
     if (fileExists(`/repos/${repoId}`)) {

+ 5 - 7
packages/system-api/src/server.ts

@@ -62,13 +62,11 @@ const main = async () => {
     await apolloServer.start();
     await apolloServer.start();
     apolloServer.applyMiddleware({ app, cors: corsOptions });
     apolloServer.applyMiddleware({ app, cors: corsOptions });
 
 
-    if (__prod__) {
-      try {
-        await datasource.runMigrations();
-      } catch (e) {
-        logger.error(e);
-        await recover();
-      }
+    try {
+      await datasource.runMigrations();
+    } catch (e) {
+      logger.error(e);
+      await recover();
     }
     }
 
 
     // Run migrations
     // Run migrations