Commit 5784b891 authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Activate pgcrypto extension fpor the generation of uuid, add password for...

Activate pgcrypto extension fpor the generation of uuid, add password for admin user + use admin user for migration
parent 10dd9b63
Pipeline #2357 passed with stages
in 13 seconds
......@@ -15,6 +15,8 @@ RUN npm install
# Bundle app source
COPY . .
CMD ["sh","-c", "npm run typeorm:migrate-ci && npm run start:prod"]
# MIGRATING variable is needed to be able to use a different user depending on the context. Admin user for migration
# simple user to run the application
CMD ["sh","-c", "export MIGRATING=1 && npm run typeorm:migrate-ci && export MIGRATING=0 && npm run start:prod"]
EXPOSE 3000
......@@ -10,6 +10,7 @@ services:
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_ADMIN_PASSWORD: ${POSTGRES_ADMIN_PASSWORD}
POSTGRES_DB: postgres
POSTGRES_HOST: database-organizations
POSTGRES_PORT: 5432
......@@ -24,6 +25,7 @@ services:
POSTGRESQL_USERNAME: user
POSTGRESQL_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRESQL_DATABASE: postgres
POSTGRESQL_POSTGRES_PASSWORD : ${POSTGRES_ADMIN_PASSWORD}
restart: unless-stopped
ports:
- ${POSTGRES_PORT}:5432
......
......@@ -14,8 +14,8 @@ const ormConfig = {
type: 'postgres',
host: process.env.POSTGRES_HOST,
port: process.env.POSTGRES_PORT,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
username: process.env.MIGRATING === '1' ? 'postgres' : process.env.POSTGRES_USER,
password: process.env.MIGRATING === '1' ? process.env.POSTGRES_ADMIN_PASSWORD : process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
entities: [`${root}/**/**.entity{.ts,.js}`],
synchronize: false,
......
import { MigrationInterface, QueryRunner } from "typeorm";
export class PutUUIDByDefaultInOrganizationModel1574772582441 implements MigrationInterface {
name = 'PutUUIDByDefaultInOrganizationModel1574772582441'
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`create extension "pgcrypto"`, undefined);
await queryRunner.query(`ALTER TABLE "organization" ALTER COLUMN "uuid" SET DEFAULT gen_random_uuid()`, undefined);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "organization" ALTER COLUMN "uuid" DROP DEFAULT`, undefined);
}
}
......@@ -10,7 +10,7 @@ export class Organization {
@ApiModelProperty()
id: number;
@Column('text', { unique: true, nullable: false })
@Column('text', { unique: true, nullable: false, default: () => 'gen_random_uuid()' })
@ApiModelProperty()
uuid: string;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment