fix: migrations config

This commit is contained in:
Nicolas Meienberger 2022-08-04 21:42:40 +02:00
parent d8af9c0eb6
commit 0932ade3f6
5 changed files with 14 additions and 17 deletions

View file

@ -3,12 +3,12 @@ import { DataSource } from 'typeorm';
export const connectionSource = new DataSource({
type: 'postgres',
host: 'localhost',
port: 5433,
username: 'postgres',
port: 5432,
username: 'tipi',
password: 'postgres',
database: 'postgres',
logging: true,
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'],
});

View file

@ -19,7 +19,8 @@
"dev": "concurrently \"npm run build:watch\" \"npm run start:dev\"",
"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",
"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": "",
"license": "ISC",

View file

@ -11,7 +11,7 @@ export class Initial1657299198975 implements MigrationInterface {
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"))',
);
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(
'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"))',
);

View file

@ -15,7 +15,7 @@ import datasource from './config/datasource';
import appsService from './modules/apps/apps.service';
import { runUpdates } from './core/updates/run';
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__
? {
@ -39,9 +39,7 @@ const main = async () => {
const app = express();
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(getSessionMiddleware());
@ -77,8 +75,8 @@ const main = async () => {
await runUpdates();
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
appsService.startAllApps();
console.info(`Server running on port ${port} 🚀 Production => ${__prod__}`);

View file

@ -39,9 +39,8 @@ fi
# Clone a repo
if [[ "$command" = "clone" ]]; then
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
echo "Repo already exists"
exit 0
@ -56,8 +55,7 @@ fi
# Update a repo
if [[ "$command" = "update" ]]; then
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
echo "Repo does not exist"
exit 0