Node.js 使用 db migration 生成数据库脚本

版权声明:本文为Martin原创文章,未经Martin允许不得转载。 https://blog.csdn.net/qq_36279445/article/details/87919023

    "db:migration": "npm run db migration:run",
    "db:migration:revert": "npm run db migration:revert",
    "db:migration:create": "ts-node ./node_modules/.bin/typeorm migration:create -n create-topic-table"

常用命令

创建migrations

fngying@ubuntu:~/Desktop/Educator/Archive$ sudo yarn run db:migration:create

yarn run v0.15.1
$ ts-node ./node_modules/.bin/typeorm migration:create -n create-topic-table 

执行(会在数据库里创建表)

fngying@ubuntu:~/Desktop/Educator/Archive$ sudo yarn run db:migration

yarn run v0.15.1
$ npm run db migration:run 

> [email protected] db /home/fngying/Desktop/Educator/Archive
> ts-node ./node_modules/.bin/typeorm "migration:run"

query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = current_schema() AND "table_name" = 'migrations'
query: SELECT * FROM "migrations" "migrations"
2 migrations are already loaded in the database.
3 migrations were found in the source code.
createTopicTable1550822002562 is the last executed migration. It was executed on Thu Feb 21 2019 23:53:22 GMT-0800 (PST).
1 migrations are new migrations that needs to be executed.
query: START TRANSACTION
query: CREATE TABLE "hashTag" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "title" varchar(255) NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp, CONSTRAINT "PK_2acaa205e080bac1bd395ac392d" PRIMARY KEY ("id"))
query: INSERT INTO "migrations"("timestamp", "name") VALUES ($1, $2) -- PARAMETERS: [1551078019455,"createHashTagTable1551078019455"]
Migration createHashTagTable1551078019455 has been executed successfully.
query: COMMIT
Done in 2.67s.

这个时候就会应用到数据库了

猜你喜欢

转载自blog.csdn.net/qq_36279445/article/details/87919023