create-skweb 3.3.2 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/templates/cjs/src/commands/migrate.js +3 -8
- package/templates/cjs/src/commands/seed.js +2 -7
- package/templates/cjs/src/config/database.js +13 -0
- package/templates/cjs/src/config/redis.js +9 -0
- package/templates/cjs/src/controllers/user.js +1 -3
- package/templates/cjs/src/cron-framework.js +5 -13
- package/templates/cjs/src/models/SysUser.js +39 -35
- package/templates/cjs/src/web-framework.js +5 -13
- package/templates/mjs/src/commands/migrate.js +3 -8
- package/templates/mjs/src/commands/seed.js +2 -7
- package/templates/mjs/src/config/database.js +11 -0
- package/templates/mjs/src/config/redis.js +7 -0
- package/templates/mjs/src/controllers/user.js +1 -3
- package/templates/mjs/src/cron-framework.js +5 -13
- package/templates/mjs/src/models/SysUser.js +37 -37
- package/templates/mjs/src/web-framework.js +5 -13
- package/templates/ts/src/commands/migrate.ts +3 -8
- package/templates/ts/src/commands/seed.ts +2 -7
- package/templates/ts/src/config/database.ts +13 -0
- package/templates/ts/src/config/redis.ts +9 -0
- package/templates/ts/src/controllers/user.ts +1 -3
- package/templates/ts/src/cron-framework.ts +5 -13
- package/templates/ts/src/models/SysUser.ts +37 -46
- package/templates/ts/src/web-framework.ts +5 -13
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
|
-
> create-skweb@3.3.
|
|
2
|
+
> create-skweb@3.3.4 prebuild
|
|
3
3
|
> tsc --outDir dist --rootDir src
|
|
4
4
|
|
|
5
5
|
⠙[1G[0K
|
|
6
|
-
> create-skweb@3.3.
|
|
6
|
+
> create-skweb@3.3.4 build
|
|
7
7
|
> rollup -c rollup.config.mjs && node scripts/inject-shebang.mjs && chmod +x dist/cli.js
|
|
8
8
|
|
|
9
9
|
⠙[1G[0K[36m
|
|
10
10
|
[1msrc/index.ts[22m → [1mdist/index.js[22m...[39m
|
|
11
11
|
[1m[33m(!) [plugin typescript] @rollup/plugin-typescript: outputToFilesystem option is defaulting to true.[39m[22m
|
|
12
|
-
[32mcreated [1mdist/index.js[22m in [
|
|
12
|
+
[32mcreated [1mdist/index.js[22m in [1m374ms[22m[39m
|
|
13
13
|
[36m
|
|
14
14
|
[1msrc/cli.ts[22m → [1mdist/cli.js[22m...[39m
|
|
15
|
-
[32mcreated [1mdist/cli.js[22m in [
|
|
15
|
+
[32mcreated [1mdist/cli.js[22m in [1m179ms[22m[39m
|
|
16
16
|
[inject-shebang] Shebang added to /Users/stayknight/projects/skweb-mono/tools/create-skweb/dist/cli.js
|
|
17
17
|
⠙[1G[0K
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# create-skweb
|
|
2
2
|
|
|
3
|
+
## 3.3.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- chore(create-skweb): v3.3.4 - 模型改为 initModel 格式,移除 declare 声明,修复 SysUser 导入方式
|
|
8
|
+
|
|
9
|
+
## 3.3.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- chore(create-skweb): v3.3.3 - 抽取共享配置模块,统一数据库和 Redis 连接配置
|
|
14
|
+
|
|
3
15
|
## 3.3.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -3,18 +3,13 @@ require('dotenv/config')
|
|
|
3
3
|
const path = require('path')
|
|
4
4
|
const { Database } = require('skweb-sequelize')
|
|
5
5
|
const { logger } = require('../utils/logger.js')
|
|
6
|
+
const { getDatabaseConfig } = require('../config/database.js')
|
|
6
7
|
|
|
7
8
|
async function runMigrate() {
|
|
8
9
|
logger.info('[migrate] Running database migrations...')
|
|
9
10
|
|
|
10
11
|
const db = new Database({
|
|
11
|
-
|
|
12
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
13
|
-
username: process.env.DB_USER || 'root',
|
|
14
|
-
password: process.env.DB_PASS || '',
|
|
15
|
-
database: process.env.DB_NAME || 'test-project',
|
|
16
|
-
dialect: process.env.DB_DIALECT || 'mysql',
|
|
17
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
12
|
+
...getDatabaseConfig(),
|
|
18
13
|
logging: process.env.DEBUG_DB === 'true' ? (msg) => logger.debug(msg) : false
|
|
19
14
|
})
|
|
20
15
|
|
|
@@ -31,4 +26,4 @@ if (require.main === module) {
|
|
|
31
26
|
})
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
module.exports = { runMigrate }
|
|
29
|
+
module.exports = { runMigrate }
|
|
@@ -4,18 +4,13 @@ const path = require('path')
|
|
|
4
4
|
const fs = require('fs')
|
|
5
5
|
const { Database } = require('skweb-sequelize')
|
|
6
6
|
const { logger } = require('../utils/logger.js')
|
|
7
|
+
const { getDatabaseConfig } = require('../config/database.js')
|
|
7
8
|
|
|
8
9
|
async function runSeed() {
|
|
9
10
|
logger.info('[seed] Initializing database with seed data...')
|
|
10
11
|
|
|
11
12
|
const db = new Database({
|
|
12
|
-
|
|
13
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
14
|
-
username: process.env.DB_USER || 'root',
|
|
15
|
-
password: process.env.DB_PASS || '',
|
|
16
|
-
database: process.env.DB_NAME || 'test-project',
|
|
17
|
-
dialect: process.env.DB_DIALECT || 'mysql',
|
|
18
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
13
|
+
...getDatabaseConfig(),
|
|
19
14
|
logging: process.env.DEBUG_DB === 'true' ? (msg) => logger.debug(msg) : false
|
|
20
15
|
})
|
|
21
16
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function getDatabaseConfig() {
|
|
2
|
+
return {
|
|
3
|
+
host: process.env.DB_HOST || '127.0.0.1',
|
|
4
|
+
port: Number(process.env.DB_PORT) || 3306,
|
|
5
|
+
username: process.env.DB_USER || 'root',
|
|
6
|
+
password: process.env.DB_PASS || '',
|
|
7
|
+
database: process.env.DB_NAME || 'test-project',
|
|
8
|
+
dialect: process.env.DB_DIALECT || 'mysql',
|
|
9
|
+
charset: process.env.DB_CHARSET || 'utf8mb4'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { getDatabaseConfig }
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
const { CronFramework } = require('skweb-framework')
|
|
3
3
|
const { logger } = require('./utils/logger.js')
|
|
4
|
+
const { getDatabaseConfig } = require('./config/database.js')
|
|
5
|
+
const { getRedisConfig } = require('./config/redis.js')
|
|
4
6
|
|
|
5
7
|
const framework = new CronFramework({
|
|
6
8
|
db: {
|
|
7
|
-
|
|
8
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
9
|
-
username: process.env.DB_USER || 'root',
|
|
10
|
-
password: process.env.DB_PASS || '',
|
|
11
|
-
database: process.env.DB_NAME || 'test-project',
|
|
12
|
-
dialect: process.env.DB_DIALECT || 'mysql',
|
|
13
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
9
|
+
...getDatabaseConfig(),
|
|
14
10
|
logging: process.env.DEBUG_DB === 'true'
|
|
15
11
|
},
|
|
16
|
-
redis:
|
|
17
|
-
host: process.env.REDIS_HOST || '127.0.0.1',
|
|
18
|
-
port: Number(process.env.REDIS_PORT) || 6379,
|
|
19
|
-
password: process.env.REDIS_PASSWORD || undefined
|
|
20
|
-
},
|
|
12
|
+
redis: getRedisConfig(),
|
|
21
13
|
channel: 'cron:task:cmd',
|
|
22
14
|
logger,
|
|
23
15
|
onSaveTask: async (taskData) => {
|
|
@@ -40,4 +32,4 @@ const framework = new CronFramework({
|
|
|
40
32
|
}
|
|
41
33
|
})
|
|
42
34
|
|
|
43
|
-
module.exports = { framework }
|
|
35
|
+
module.exports = { framework }
|
|
@@ -1,38 +1,42 @@
|
|
|
1
1
|
const { Model, DataTypes } = require('sequelize')
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
3
|
+
class SysUser extends Model {
|
|
4
|
+
static initModel(sequelize) {
|
|
5
|
+
SysUser.init({
|
|
6
|
+
id: {
|
|
7
|
+
type: DataTypes.INTEGER,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
autoIncrement: true
|
|
10
|
+
},
|
|
11
|
+
username: {
|
|
12
|
+
type: DataTypes.STRING(50),
|
|
13
|
+
allowNull: false,
|
|
14
|
+
unique: true
|
|
15
|
+
},
|
|
16
|
+
password: {
|
|
17
|
+
type: DataTypes.STRING(255),
|
|
18
|
+
allowNull: false
|
|
19
|
+
},
|
|
20
|
+
email: {
|
|
21
|
+
type: DataTypes.STRING(100)
|
|
22
|
+
},
|
|
23
|
+
phone: {
|
|
24
|
+
type: DataTypes.STRING(20)
|
|
25
|
+
},
|
|
26
|
+
status: {
|
|
27
|
+
type: DataTypes.TINYINT,
|
|
28
|
+
defaultValue: 1
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
sequelize,
|
|
32
|
+
modelName: 'SysUser',
|
|
33
|
+
tableName: 'sys_users',
|
|
34
|
+
timestamps: true,
|
|
35
|
+
underscored: true
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return SysUser
|
|
39
|
+
}
|
|
38
40
|
}
|
|
41
|
+
|
|
42
|
+
module.exports = { SysUser }
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
const { WebFramework } = require('skweb-framework')
|
|
3
|
+
const { getDatabaseConfig } = require('./config/database.js')
|
|
4
|
+
const { getRedisConfig } = require('./config/redis.js')
|
|
3
5
|
|
|
4
6
|
const framework = new WebFramework({
|
|
5
7
|
db: {
|
|
6
|
-
|
|
7
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
8
|
-
username: process.env.DB_USER || 'root',
|
|
9
|
-
password: process.env.DB_PASS || '',
|
|
10
|
-
database: process.env.DB_NAME || 'test-project',
|
|
11
|
-
dialect: process.env.DB_DIALECT || 'mysql',
|
|
12
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
8
|
+
...getDatabaseConfig(),
|
|
13
9
|
logging: process.env.DEBUG_DB === 'true'
|
|
14
10
|
},
|
|
15
|
-
redis:
|
|
16
|
-
host: process.env.REDIS_HOST || '127.0.0.1',
|
|
17
|
-
port: Number(process.env.REDIS_PORT) || 6379,
|
|
18
|
-
password: process.env.REDIS_PASSWORD || undefined
|
|
19
|
-
}
|
|
11
|
+
redis: getRedisConfig()
|
|
20
12
|
})
|
|
21
13
|
|
|
22
|
-
module.exports = { framework }
|
|
14
|
+
module.exports = { framework }
|
|
@@ -4,6 +4,7 @@ import path from 'path'
|
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
5
|
import { Database } from 'skweb-sequelize'
|
|
6
6
|
import logger from '../utils/logger.js'
|
|
7
|
+
import { getDatabaseConfig } from '../config/database.js'
|
|
7
8
|
|
|
8
9
|
const __filename = fileURLToPath(import.meta.url)
|
|
9
10
|
const __dirname = path.dirname(__filename)
|
|
@@ -12,13 +13,7 @@ async function runMigrate() {
|
|
|
12
13
|
logger.info('[migrate] Running database migrations...')
|
|
13
14
|
|
|
14
15
|
const db = new Database({
|
|
15
|
-
|
|
16
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
17
|
-
username: process.env.DB_USER || 'root',
|
|
18
|
-
password: process.env.DB_PASS || '',
|
|
19
|
-
database: process.env.DB_NAME || 'test-project',
|
|
20
|
-
dialect: process.env.DB_DIALECT || 'mysql',
|
|
21
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
16
|
+
...getDatabaseConfig(),
|
|
22
17
|
logging: process.env.DEBUG_DB === 'true' ? (msg) => logger.debug(msg) : false
|
|
23
18
|
})
|
|
24
19
|
|
|
@@ -34,4 +29,4 @@ if (isMainModule) {
|
|
|
34
29
|
logger.error('[migrate] Fatal error:', err)
|
|
35
30
|
process.exit(1)
|
|
36
31
|
})
|
|
37
|
-
}
|
|
32
|
+
}
|
|
@@ -4,6 +4,7 @@ import path from 'path'
|
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
5
|
import { Database } from 'skweb-sequelize'
|
|
6
6
|
import logger from '../utils/logger.js'
|
|
7
|
+
import { getDatabaseConfig } from '../config/database.js'
|
|
7
8
|
|
|
8
9
|
const __filename = fileURLToPath(import.meta.url)
|
|
9
10
|
const __dirname = path.dirname(__filename)
|
|
@@ -12,13 +13,7 @@ async function runSeed() {
|
|
|
12
13
|
logger.info('[seed] Initializing database with seed data...')
|
|
13
14
|
|
|
14
15
|
const db = new Database({
|
|
15
|
-
|
|
16
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
17
|
-
username: process.env.DB_USER || 'root',
|
|
18
|
-
password: process.env.DB_PASS || '',
|
|
19
|
-
database: process.env.DB_NAME || 'test-project',
|
|
20
|
-
dialect: process.env.DB_DIALECT || 'mysql',
|
|
21
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
16
|
+
...getDatabaseConfig(),
|
|
22
17
|
logging: process.env.DEBUG_DB === 'true' ? (msg) => logger.debug(msg) : false
|
|
23
18
|
})
|
|
24
19
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function getDatabaseConfig() {
|
|
2
|
+
return {
|
|
3
|
+
host: process.env.DB_HOST || '127.0.0.1',
|
|
4
|
+
port: Number(process.env.DB_PORT) || 3306,
|
|
5
|
+
username: process.env.DB_USER || 'root',
|
|
6
|
+
password: process.env.DB_PASS || '',
|
|
7
|
+
database: process.env.DB_NAME || 'test-project',
|
|
8
|
+
dialect: process.env.DB_DIALECT || 'mysql',
|
|
9
|
+
charset: process.env.DB_CHARSET || 'utf8mb4'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import { CronFramework } from 'skweb-framework'
|
|
3
3
|
import logger from './utils/logger.js'
|
|
4
|
+
import { getDatabaseConfig } from './config/database.js'
|
|
5
|
+
import { getRedisConfig } from './config/redis.js'
|
|
4
6
|
|
|
5
7
|
const framework = new CronFramework({
|
|
6
8
|
db: {
|
|
7
|
-
|
|
8
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
9
|
-
username: process.env.DB_USER || 'root',
|
|
10
|
-
password: process.env.DB_PASS || '',
|
|
11
|
-
database: process.env.DB_NAME || 'test-project',
|
|
12
|
-
dialect: process.env.DB_DIALECT || 'mysql',
|
|
13
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
9
|
+
...getDatabaseConfig(),
|
|
14
10
|
logging: process.env.DEBUG_DB === 'true'
|
|
15
11
|
},
|
|
16
|
-
redis:
|
|
17
|
-
host: process.env.REDIS_HOST || '127.0.0.1',
|
|
18
|
-
port: Number(process.env.REDIS_PORT) || 6379,
|
|
19
|
-
password: process.env.REDIS_PASSWORD || undefined
|
|
20
|
-
},
|
|
12
|
+
redis: getRedisConfig(),
|
|
21
13
|
channel: 'cron:task:cmd',
|
|
22
14
|
logger,
|
|
23
15
|
onSaveTask: async (taskData) => {
|
|
@@ -40,4 +32,4 @@ const framework = new CronFramework({
|
|
|
40
32
|
}
|
|
41
33
|
})
|
|
42
34
|
|
|
43
|
-
export { framework }
|
|
35
|
+
export { framework }
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
import { Model, DataTypes } from 'sequelize'
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export class SysUser extends Model {
|
|
4
|
+
static initModel(sequelize) {
|
|
5
|
+
SysUser.init({
|
|
6
|
+
id: {
|
|
7
|
+
type: DataTypes.INTEGER,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
autoIncrement: true
|
|
10
|
+
},
|
|
11
|
+
username: {
|
|
12
|
+
type: DataTypes.STRING(50),
|
|
13
|
+
allowNull: false,
|
|
14
|
+
unique: true
|
|
15
|
+
},
|
|
16
|
+
password: {
|
|
17
|
+
type: DataTypes.STRING(255),
|
|
18
|
+
allowNull: false
|
|
19
|
+
},
|
|
20
|
+
email: {
|
|
21
|
+
type: DataTypes.STRING(100)
|
|
22
|
+
},
|
|
23
|
+
phone: {
|
|
24
|
+
type: DataTypes.STRING(20)
|
|
25
|
+
},
|
|
26
|
+
status: {
|
|
27
|
+
type: DataTypes.TINYINT,
|
|
28
|
+
defaultValue: 1
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
sequelize,
|
|
32
|
+
modelName: 'SysUser',
|
|
33
|
+
tableName: 'sys_users',
|
|
34
|
+
timestamps: true,
|
|
35
|
+
underscored: true
|
|
36
|
+
})
|
|
5
37
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
primaryKey: true,
|
|
10
|
-
autoIncrement: true
|
|
11
|
-
},
|
|
12
|
-
username: {
|
|
13
|
-
type: DataTypes.STRING(50),
|
|
14
|
-
allowNull: false,
|
|
15
|
-
unique: true
|
|
16
|
-
},
|
|
17
|
-
password: {
|
|
18
|
-
type: DataTypes.STRING(255),
|
|
19
|
-
allowNull: false
|
|
20
|
-
},
|
|
21
|
-
email: {
|
|
22
|
-
type: DataTypes.STRING(100)
|
|
23
|
-
},
|
|
24
|
-
phone: {
|
|
25
|
-
type: DataTypes.STRING(20)
|
|
26
|
-
},
|
|
27
|
-
status: {
|
|
28
|
-
type: DataTypes.TINYINT,
|
|
29
|
-
defaultValue: 1
|
|
30
|
-
}
|
|
31
|
-
}, {
|
|
32
|
-
sequelize,
|
|
33
|
-
modelName: 'SysUser',
|
|
34
|
-
tableName: 'sys_users',
|
|
35
|
-
timestamps: true,
|
|
36
|
-
underscored: true
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
return SysUser
|
|
40
|
-
}
|
|
38
|
+
return SysUser
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import { WebFramework } from 'skweb-framework'
|
|
3
|
+
import { getDatabaseConfig } from './config/database.js'
|
|
4
|
+
import { getRedisConfig } from './config/redis.js'
|
|
3
5
|
|
|
4
6
|
const framework = new WebFramework({
|
|
5
7
|
db: {
|
|
6
|
-
|
|
7
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
8
|
-
username: process.env.DB_USER || 'root',
|
|
9
|
-
password: process.env.DB_PASS || '',
|
|
10
|
-
database: process.env.DB_NAME || 'test-project',
|
|
11
|
-
dialect: process.env.DB_DIALECT || 'mysql',
|
|
12
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
8
|
+
...getDatabaseConfig(),
|
|
13
9
|
logging: process.env.DEBUG_DB === 'true'
|
|
14
10
|
},
|
|
15
|
-
redis:
|
|
16
|
-
host: process.env.REDIS_HOST || '127.0.0.1',
|
|
17
|
-
port: Number(process.env.REDIS_PORT) || 6379,
|
|
18
|
-
password: process.env.REDIS_PASSWORD || undefined
|
|
19
|
-
}
|
|
11
|
+
redis: getRedisConfig()
|
|
20
12
|
})
|
|
21
13
|
|
|
22
|
-
export { framework }
|
|
14
|
+
export { framework }
|
|
@@ -4,6 +4,7 @@ import path from 'path'
|
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
5
|
import { Database } from 'skweb-sequelize'
|
|
6
6
|
import logger from '../utils/logger.js'
|
|
7
|
+
import { getDatabaseConfig } from '../config/database.js'
|
|
7
8
|
|
|
8
9
|
const __filename = fileURLToPath(import.meta.url)
|
|
9
10
|
const __dirname = path.dirname(__filename)
|
|
@@ -12,13 +13,7 @@ async function runMigrate(): Promise<void> {
|
|
|
12
13
|
logger.info('[migrate] Running database migrations...')
|
|
13
14
|
|
|
14
15
|
const db = new Database({
|
|
15
|
-
|
|
16
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
17
|
-
username: process.env.DB_USER || 'root',
|
|
18
|
-
password: process.env.DB_PASS || '',
|
|
19
|
-
database: process.env.DB_NAME || 'test-project',
|
|
20
|
-
dialect: (process.env.DB_DIALECT as 'mysql' | 'postgres' | 'sqlite' | 'mariadb') || 'mysql',
|
|
21
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
16
|
+
...getDatabaseConfig(),
|
|
22
17
|
logging: process.env.DEBUG_DB === 'true' ? (msg: string) => logger.debug(msg) : false
|
|
23
18
|
})
|
|
24
19
|
|
|
@@ -34,4 +29,4 @@ if (isMainModule) {
|
|
|
34
29
|
logger.error('[migrate] Fatal error:', err)
|
|
35
30
|
process.exit(1)
|
|
36
31
|
})
|
|
37
|
-
}
|
|
32
|
+
}
|
|
@@ -4,6 +4,7 @@ import path from 'path'
|
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
5
|
import { Database } from 'skweb-sequelize'
|
|
6
6
|
import logger from '../utils/logger.js'
|
|
7
|
+
import { getDatabaseConfig } from '../config/database.js'
|
|
7
8
|
|
|
8
9
|
const __filename = fileURLToPath(import.meta.url)
|
|
9
10
|
const __dirname = path.dirname(__filename)
|
|
@@ -12,13 +13,7 @@ async function runSeed(): Promise<void> {
|
|
|
12
13
|
logger.info('[seed] Initializing database with seed data...')
|
|
13
14
|
|
|
14
15
|
const db = new Database({
|
|
15
|
-
|
|
16
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
17
|
-
username: process.env.DB_USER || 'root',
|
|
18
|
-
password: process.env.DB_PASS || '',
|
|
19
|
-
database: process.env.DB_NAME || 'test-project',
|
|
20
|
-
dialect: (process.env.DB_DIALECT as 'mysql' | 'postgres' | 'sqlite' | 'mariadb') || 'mysql',
|
|
21
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
16
|
+
...getDatabaseConfig(),
|
|
22
17
|
logging: process.env.DEBUG_DB === 'true' ? (msg: string) => logger.debug(msg) : false
|
|
23
18
|
})
|
|
24
19
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DatabaseConfig } from 'skweb-sequelize'
|
|
2
|
+
|
|
3
|
+
export function getDatabaseConfig(): DatabaseConfig {
|
|
4
|
+
return {
|
|
5
|
+
host: process.env.DB_HOST || '127.0.0.1',
|
|
6
|
+
port: Number(process.env.DB_PORT) || 3306,
|
|
7
|
+
username: process.env.DB_USER || 'root',
|
|
8
|
+
password: process.env.DB_PASS || '',
|
|
9
|
+
database: process.env.DB_NAME || 'test-project',
|
|
10
|
+
dialect: (process.env.DB_DIALECT as any) || 'mysql',
|
|
11
|
+
charset: process.env.DB_CHARSET || 'utf8mb4'
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RedisOptions } from 'skweb-redis'
|
|
2
|
+
|
|
3
|
+
export function getRedisConfig(): RedisOptions {
|
|
4
|
+
return {
|
|
5
|
+
host: process.env.REDIS_HOST || '127.0.0.1',
|
|
6
|
+
port: Number(process.env.REDIS_PORT) || 6379,
|
|
7
|
+
password: process.env.REDIS_PASSWORD || undefined
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import { CronFramework } from 'skweb-framework'
|
|
3
3
|
import logger from './utils/logger.js'
|
|
4
|
+
import { getDatabaseConfig } from './config/database.js'
|
|
5
|
+
import { getRedisConfig } from './config/redis.js'
|
|
4
6
|
|
|
5
7
|
const framework = new CronFramework({
|
|
6
8
|
db: {
|
|
7
|
-
|
|
8
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
9
|
-
username: process.env.DB_USER || 'root',
|
|
10
|
-
password: process.env.DB_PASS || '',
|
|
11
|
-
database: process.env.DB_NAME || 'test-project',
|
|
12
|
-
dialect: (process.env.DB_DIALECT as any) || 'mysql',
|
|
13
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
9
|
+
...getDatabaseConfig(),
|
|
14
10
|
logging: process.env.DEBUG_DB === 'true'
|
|
15
11
|
},
|
|
16
|
-
redis:
|
|
17
|
-
host: process.env.REDIS_HOST || '127.0.0.1',
|
|
18
|
-
port: Number(process.env.REDIS_PORT) || 6379,
|
|
19
|
-
password: process.env.REDIS_PASSWORD || undefined
|
|
20
|
-
},
|
|
12
|
+
redis: getRedisConfig(),
|
|
21
13
|
channel: 'cron:task:cmd',
|
|
22
14
|
logger,
|
|
23
15
|
onSaveTask: async (taskData: { taskId: string; cache: unknown; data: unknown }) => {
|
|
@@ -40,4 +32,4 @@ const framework = new CronFramework({
|
|
|
40
32
|
}
|
|
41
33
|
})
|
|
42
34
|
|
|
43
|
-
export { framework }
|
|
35
|
+
export { framework }
|
|
@@ -1,49 +1,40 @@
|
|
|
1
1
|
import { Model, DataTypes, type Sequelize, type ModelStatic } from 'sequelize'
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
type: DataTypes.TINYINT,
|
|
38
|
-
defaultValue: 1
|
|
39
|
-
}
|
|
40
|
-
}, {
|
|
41
|
-
sequelize,
|
|
42
|
-
modelName: 'SysUser',
|
|
43
|
-
tableName: 'sys_users',
|
|
44
|
-
timestamps: true,
|
|
45
|
-
underscored: true
|
|
46
|
-
})
|
|
3
|
+
export class SysUser extends Model {
|
|
4
|
+
static initModel(sequelize: Sequelize): ModelStatic<Model> {
|
|
5
|
+
SysUser.init({
|
|
6
|
+
id: {
|
|
7
|
+
type: DataTypes.INTEGER,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
autoIncrement: true
|
|
10
|
+
},
|
|
11
|
+
username: {
|
|
12
|
+
type: DataTypes.STRING(50),
|
|
13
|
+
allowNull: false,
|
|
14
|
+
unique: true
|
|
15
|
+
},
|
|
16
|
+
password: {
|
|
17
|
+
type: DataTypes.STRING(255),
|
|
18
|
+
allowNull: false
|
|
19
|
+
},
|
|
20
|
+
email: {
|
|
21
|
+
type: DataTypes.STRING(100)
|
|
22
|
+
},
|
|
23
|
+
phone: {
|
|
24
|
+
type: DataTypes.STRING(20)
|
|
25
|
+
},
|
|
26
|
+
status: {
|
|
27
|
+
type: DataTypes.TINYINT,
|
|
28
|
+
defaultValue: 1
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
sequelize,
|
|
32
|
+
modelName: 'SysUser',
|
|
33
|
+
tableName: 'sys_users',
|
|
34
|
+
timestamps: true,
|
|
35
|
+
underscored: true
|
|
36
|
+
})
|
|
47
37
|
|
|
48
|
-
|
|
49
|
-
}
|
|
38
|
+
return SysUser
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import { WebFramework } from 'skweb-framework'
|
|
3
|
+
import { getDatabaseConfig } from './config/database.js'
|
|
4
|
+
import { getRedisConfig } from './config/redis.js'
|
|
3
5
|
|
|
4
6
|
const framework = new WebFramework({
|
|
5
7
|
db: {
|
|
6
|
-
|
|
7
|
-
port: Number(process.env.DB_PORT) || 3306,
|
|
8
|
-
username: process.env.DB_USER || 'root',
|
|
9
|
-
password: process.env.DB_PASS || '',
|
|
10
|
-
database: process.env.DB_NAME || 'test-project',
|
|
11
|
-
dialect: (process.env.DB_DIALECT as any) || 'mysql',
|
|
12
|
-
charset: process.env.DB_CHARSET || 'utf8mb4',
|
|
8
|
+
...getDatabaseConfig(),
|
|
13
9
|
logging: process.env.DEBUG_DB === 'true'
|
|
14
10
|
},
|
|
15
|
-
redis:
|
|
16
|
-
host: process.env.REDIS_HOST || '127.0.0.1',
|
|
17
|
-
port: Number(process.env.REDIS_PORT) || 6379,
|
|
18
|
-
password: process.env.REDIS_PASSWORD || undefined
|
|
19
|
-
}
|
|
11
|
+
redis: getRedisConfig()
|
|
20
12
|
})
|
|
21
13
|
|
|
22
|
-
export { framework }
|
|
14
|
+
export { framework }
|