Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
### seed 填充数据 | ||
|
||
- 前置操作 参考 01docker.md 内容,新建好容器,配置好数据库连接 | ||
|
||
- 开第一个终端 `yarn dev` | ||
- 可以编译我们的 typeorm代码 | ||
|
||
- 开第二个终端执行数据库迁移 | ||
|
||
```$xslt | ||
# 创建数据库表 | ||
yarn migration:run | ||
# revert操作 | ||
yarn migration:revert | ||
``` | ||
|
||
- 填充数据 | ||
|
||
``` | ||
# 项目根目录 | ||
node dist/seed.js | ||
``` | ||
|
||
- 进入docker容器内部查询 | ||
|
||
``` | ||
select * from posts; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import "reflect-metadata"; | ||
import {createConnection} from "typeorm"; | ||
import {Post} from "./entity/Post"; | ||
|
||
createConnection().then(async connection => { | ||
const posts = await connection.manager.find(Post); | ||
|
||
if (posts.length === 0) { | ||
await connection.manager.save([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(n => { | ||
return new Post({title: `Post ${n}`, content: `这是我的第${n}篇文章`}); | ||
})); | ||
console.log('posts 数据填充了'); | ||
} | ||
connection.close(); | ||
}).catch(error => console.log(error)); |