Skip to content

Commit 3081d69

Browse files
committed
⭐(db) add migration files
1 parent 7fb5999 commit 3081d69

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ RUN cd /code/backend \
2424
&& npm run build
2525

2626
WORKDIR /code/frontend
27-
CMD cd /code/backend && pm2 start dist/src/main.js && pm2 start http-server.js && cd /code/frontend && npm run start
27+
CMD cd /code/backend && npm run typeorm:run && pm2 start dist/src/main.js && pm2 start http-server.js && cd /code/frontend && npm run start
2828

2929

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {MigrationInterface, QueryRunner} from "typeorm";
2+
3+
export class init1582966843426 implements MigrationInterface {
4+
name = 'init1582966843426'
5+
6+
public async up(queryRunner: QueryRunner): Promise<any> {
7+
await queryRunner.query("CREATE TABLE `blog_table` (`id` int NOT NULL AUTO_INCREMENT, `author` varchar(255) NOT NULL, `site` varchar(255) NOT NULL, `stableSite` varchar(255) NOT NULL, `siteName` varchar(255) NOT NULL, `feed` varchar(512) NOT NULL, `stableFeed` varchar(512) NOT NULL, `createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updatedAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB", undefined);
8+
await queryRunner.query("CREATE TABLE `article_table` (`id` int NOT NULL AUTO_INCREMENT, `url` varchar(512) NOT NULL, `slug` varchar(512) NOT NULL, `stableUrl` varchar(512) NOT NULL, `title` varchar(512) NOT NULL, `tags` varchar(512) NOT NULL, `summary` longtext NOT NULL, `content` longtext NOT NULL, `date` datetime NOT NULL, `views` int NOT NULL DEFAULT 0, `createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updatedAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `blogId` int NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB", undefined);
9+
await queryRunner.query("ALTER TABLE `article_table` ADD CONSTRAINT `FK_e2c1e79207463c012ad8dd9dd57` FOREIGN KEY (`blogId`) REFERENCES `blog_table`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION", undefined);
10+
}
11+
12+
public async down(queryRunner: QueryRunner): Promise<any> {
13+
await queryRunner.query("ALTER TABLE `article_table` DROP FOREIGN KEY `FK_e2c1e79207463c012ad8dd9dd57`", undefined);
14+
await queryRunner.query("DROP TABLE `article_table`", undefined);
15+
await queryRunner.query("DROP TABLE `blog_table`", undefined);
16+
}
17+
18+
}

backend/src/ormconfig.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ConnectionOptions } from 'typeorm';
22
import { DATABASE_HOST, DATABASE_NAME, DATABASE_PASSWORD, DATABASE_PORT, DATABASE_TYPE, DATABASE_USERNAME } from '../settings';
33

44

5-
console.log({__dirname})
65
// Check typeORM documentation for more information.
76
const config: ConnectionOptions = {
87
type: DATABASE_TYPE as any,
@@ -21,7 +20,7 @@ const config: ConnectionOptions = {
2120
// you can disable this if you prefer running migration manually.
2221
migrationsRun: false,
2322
loggerLevel: "error",
24-
logging: true,
23+
// logging: true,
2524
// logger: 'file',
2625

2726
// Allow both start:prod and start:dev to use migrations

0 commit comments

Comments
 (0)