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


    "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 

> educator-api@1.0.0 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.

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值