"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.
这个时候就会应用到数据库了