fix: migrations

This commit is contained in:
Nicolas Meienberger 2022-08-04 22:39:31 +02:00
parent 0932ade3f6
commit 09f7dcefc9
7 changed files with 27 additions and 14 deletions

View file

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

View file

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

View file

@ -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"`);
}
}

View file

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

View file

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

View file

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

View file

@ -62,13 +62,11 @@ const main = async () => {
await apolloServer.start();
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