forked from eggjs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: auto sync db on local env (eggjs#115)
- Loading branch information
Showing
6 changed files
with
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const initDatabase = require('./config/database/init'); | ||
|
||
class AppBootHook { | ||
constructor(app) { | ||
this.app = app; | ||
} | ||
|
||
async didLoad() { | ||
await initDatabase(this.app); | ||
} | ||
} | ||
|
||
module.exports = AppBootHook; |
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 @@ | ||
environment: | ||
matrix: | ||
- nodejs_version: '10' | ||
- nodejs_version: '12' | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version | ||
- npm i npminstall && node_modules\.bin\npminstall | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- npm run test | ||
|
||
build: off |
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,21 @@ | ||
/* eslint valid-jsdoc: "off" */ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
module.exports = () => { | ||
/** | ||
* built-in config | ||
* @type {Egg.EggAppConfig} | ||
**/ | ||
const config = {}; | ||
|
||
config.orm = { | ||
database: path.join(__dirname, '..', 'todos_unittest.sqlite3'), | ||
}; | ||
|
||
return { | ||
...config, | ||
}; | ||
}; |
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,16 @@ | ||
'use strict'; | ||
|
||
// init database here | ||
module.exports = async app => { | ||
// sync database defines | ||
await app.model.sync(); | ||
|
||
if (app.config.env === 'unittest') { | ||
await app.model.Todo.remove({}, true); | ||
await app.model.Todo.bulkCreate([ | ||
{ id: 1, title: 'Read history of Node.js', completed: true }, | ||
{ id: 2, title: 'Learn Koa', completed: true }, | ||
{ id: 3, title: 'Star Egg', completed: false }, | ||
]); | ||
} | ||
}; |
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 |
---|---|---|
|
@@ -42,6 +42,9 @@ | |
"type": "git", | ||
"url": "" | ||
}, | ||
"ci": { | ||
"version": "10, 12" | ||
}, | ||
"author": "TZ <[email protected]>", | ||
"license": "MIT" | ||
} |
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