Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions development.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN yarn cache clean && yarn install
FROM node:16-bullseye-slim as development

ENV NODE_PATH=/node_modules
ENV PATH="/node_modules/.bin:${PATH}"
COPY --from=dependencies /dependencies/node_modules /node_modules

WORKDIR /app
Expand Down
8 changes: 8 additions & 0 deletions run-migrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh
set -e

CONTAINER_NAME="wallet-backend-server"

echo "Running migrations inside container $CONTAINER_NAME..."
docker exec -it $CONTAINER_NAME yarn typeorm migration:run
echo "Migrations completed."
5 changes: 4 additions & 1 deletion src/AppDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const AppDataSource: DataSource = new DataSource({
password: config.db.password,
database: config.db.dbname,
entities: [__dirname + "/entities/*.entity.{js,ts}"],
synchronize: true
migrations: [
__dirname + "/migrations/*.{js,ts}"
],
synchronize: false,
});

(async function initDataSource() {
Expand Down
2 changes: 1 addition & 1 deletion src/entities/CredentialIssuer.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CredentialIssuerEntity {


// Explicit default to workaround a bug in typeorm: https://github.com/typeorm/typeorm/issues/3076#issuecomment-703128687
@Column({ nullable: true, type: "tinyint" })
@Column({ nullable: true, type: "tinyint", default: () => "NULL" })
visible: boolean;
}

Expand Down
38 changes: 38 additions & 0 deletions src/migrations/1762258689037-RemoveFcmToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { MigrationInterface, QueryRunner, TableForeignKey } from "typeorm";

export class RemoveFcmToken1762258689037 implements MigrationInterface {
name = 'RemoveFcmToken1762258689037';

public async up(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable("fcm_token");
// Name-agnostic drop of user entity's one-to-many relationship
if (table) {
const fk = table.foreignKeys.find(k => k.columnNames.includes("userId"));
if (fk) await queryRunner.dropForeignKey("fcm_token", fk);
await queryRunner.query("DROP TABLE `fcm_token`");
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE \`fcm_token\` (
\`id\` int NOT NULL AUTO_INCREMENT,
\`value\` varchar(255) NOT NULL,
\`userId\` int NULL,
PRIMARY KEY (\`id\`)
) ENGINE=InnoDB
`);

await queryRunner.createForeignKey(
"fcm_token",
new TableForeignKey({
columnNames: ["userId"],
referencedTableName: "user",
referencedColumnNames: ["id"],
onDelete: "NO ACTION",
onUpdate: "NO ACTION",
})
);
}

}