Nicolas Meienberger 2 лет назад
Родитель
Сommit
0932ade3f6

+ 4 - 4
packages/system-api/ormconfig.ts

@@ -3,12 +3,12 @@ import { DataSource } from 'typeorm';
 export const connectionSource = new DataSource({
 export const connectionSource = new DataSource({
   type: 'postgres',
   type: 'postgres',
   host: 'localhost',
   host: 'localhost',
-  port: 5433,
-  username: 'postgres',
+  port: 5432,
+  username: 'tipi',
   password: 'postgres',
   password: 'postgres',
   database: 'postgres',
   database: 'postgres',
   logging: true,
   logging: true,
   synchronize: false,
   synchronize: false,
-  entities: [process.cwd() + '/src/modules/**/*.entity.ts'],
-  migrations: [process.cwd() + '/src/config/migrations/*.ts'],
+  entities: ['/src/modules/**/*.entity.ts'],
+  migrations: ['/src/config/migrations/*.ts'],
 });
 });

+ 2 - 1
packages/system-api/package.json

@@ -19,7 +19,8 @@
     "dev": "concurrently \"npm run build:watch\" \"npm run start:dev\"",
     "dev": "concurrently \"npm run build:watch\" \"npm run start:dev\"",
     "start": "NODE_ENV=production && node --experimental-specifier-resolution=node dist/server.js",
     "start": "NODE_ENV=production && node --experimental-specifier-resolution=node dist/server.js",
     "typeorm": "node --experimental-specifier-resolution=node --loader ts-node/esm ./node_modules/typeorm/cli.js -d ormconfig.ts",
     "typeorm": "node --experimental-specifier-resolution=node --loader ts-node/esm ./node_modules/typeorm/cli.js -d ormconfig.ts",
-    "migration:generate": "npm run typeorm migration:generate ./src/config/migrations/$npm_config_name"
+    "migration:generate": "npm run typeorm migration:generate ./src/config/migrations/$npm_config_name",
+    "migration:create": "node --experimental-specifier-resolution=node --loader ts-node/esm ./node_modules/typeorm/cli.js migration:create ./src/config/migrations/$npm_config_name"
   },
   },
   "author": "",
   "author": "",
   "license": "ISC",
   "license": "ISC",

+ 1 - 1
packages/system-api/src/config/migrations/1657299198975-Initial.ts

@@ -11,7 +11,7 @@ export class Initial1657299198975 implements MigrationInterface {
     await queryRunner.query(
     await queryRunner.query(
       'CREATE TABLE "user" ("id" SERIAL NOT NULL, "username" character varying NOT NULL, "password" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_78a916df40e02a9deb1c4b75edb" UNIQUE ("username"), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))',
       'CREATE TABLE "user" ("id" SERIAL NOT NULL, "username" character varying NOT NULL, "password" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_78a916df40e02a9deb1c4b75edb" UNIQUE ("username"), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))',
     );
     );
-    await queryRunner.query('CREATE TYPE "public"."app_status_enum" AS ENUM(\'running\', \'stopped\', \'installing\', \'uninstalling\', \'stopping\', \'starting\', \'missing\')');
+    await queryRunner.query("CREATE TYPE \"public\".\"app_status_enum\" AS ENUM('running', 'stopped', 'installing', 'uninstalling', 'stopping', 'starting', 'missing')");
     await queryRunner.query(
     await queryRunner.query(
       'CREATE TABLE "app" ("id" character varying NOT NULL, "status" "public"."app_status_enum" NOT NULL DEFAULT \'stopped\', "lastOpened" TIMESTAMP WITH TIME ZONE DEFAULT now(), "numOpened" integer NOT NULL DEFAULT \'0\', "config" jsonb NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_9478629fc093d229df09e560aea" UNIQUE ("id"), CONSTRAINT "PK_9478629fc093d229df09e560aea" PRIMARY KEY ("id"))',
       'CREATE TABLE "app" ("id" character varying NOT NULL, "status" "public"."app_status_enum" NOT NULL DEFAULT \'stopped\', "lastOpened" TIMESTAMP WITH TIME ZONE DEFAULT now(), "numOpened" integer NOT NULL DEFAULT \'0\', "config" jsonb NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_9478629fc093d229df09e560aea" UNIQUE ("id"), CONSTRAINT "PK_9478629fc093d229df09e560aea" PRIMARY KEY ("id"))',
     );
     );

+ 4 - 6
packages/system-api/src/server.ts

@@ -15,7 +15,7 @@ import datasource from './config/datasource';
 import appsService from './modules/apps/apps.service';
 import appsService from './modules/apps/apps.service';
 import { runUpdates } from './core/updates/run';
 import { runUpdates } from './core/updates/run';
 import recover from './core/updates/recover-migrations';
 import recover from './core/updates/recover-migrations';
-import { cloneRepo, getRepoId, updateRepo } from './helpers/repo-helpers';
+import { cloneRepo, updateRepo } from './helpers/repo-helpers';
 
 
 let corsOptions = __prod__
 let corsOptions = __prod__
   ? {
   ? {
@@ -39,9 +39,7 @@ const main = async () => {
     const app = express();
     const app = express();
     const port = 3001;
     const port = 3001;
 
 
-    const repoId = await getRepoId(config.APPS_REPOSITORY);
-
-    app.use(express.static(`${config.ROOT_FOLDER}/repos/${repoId}`));
+    app.use(express.static(`${config.ROOT_FOLDER}/repos/${config.APPS_REPO_ID}`));
     app.use(cors(corsOptions));
     app.use(cors(corsOptions));
     app.use(getSessionMiddleware());
     app.use(getSessionMiddleware());
 
 
@@ -77,8 +75,8 @@ const main = async () => {
     await runUpdates();
     await runUpdates();
 
 
     httpServer.listen(port, async () => {
     httpServer.listen(port, async () => {
-      await cloneRepo(config.APPS_REPOSITORY);
-      await updateRepo(config.APPS_REPOSITORY);
+      await cloneRepo(config.APPS_REPO_ID);
+      await updateRepo(config.APPS_REPO_ID);
       // Start apps
       // Start apps
       appsService.startAllApps();
       appsService.startAllApps();
       console.info(`Server running on port ${port} 🚀 Production => ${__prod__}`);
       console.info(`Server running on port ${port} 🚀 Production => ${__prod__}`);

+ 3 - 5
scripts/git.sh

@@ -39,9 +39,8 @@ fi
 # Clone a repo
 # Clone a repo
 if [[ "$command" = "clone" ]]; then
 if [[ "$command" = "clone" ]]; then
     repo="$2"
     repo="$2"
-    repo_hash="$(get_hash "${repo}")"
-    echo "Cloning ${repo} to ${ROOT_FOLDER}/repos/${repo_hash}"
-    repo_dir="${ROOT_FOLDER}/repos/${repo_hash}"
+    echo "Cloning ${repo} to ${ROOT_FOLDER}/repos/${repo}"
+    repo_dir="${ROOT_FOLDER}/repos/${repo}"
     if [ -d "${repo_dir}" ]; then
     if [ -d "${repo_dir}" ]; then
         echo "Repo already exists"
         echo "Repo already exists"
         exit 0
         exit 0
@@ -56,8 +55,7 @@ fi
 # Update a repo
 # Update a repo
 if [[ "$command" = "update" ]]; then
 if [[ "$command" = "update" ]]; then
     repo="$2"
     repo="$2"
-    repo_hash="$(get_hash "${repo}")"
-    repo_dir="${ROOT_FOLDER}/repos/${repo_hash}"
+    repo_dir="${ROOT_FOLDER}/repos/${repo}"
     if [ ! -d "${repo_dir}" ]; then
     if [ ! -d "${repo_dir}" ]; then
         echo "Repo does not exist"
         echo "Repo does not exist"
         exit 0
         exit 0