mevn-orm 4.0.0 → 4.0.1
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/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/src/config.d.ts +46 -0
- package/dist/src/config.js +196 -0
- package/dist/src/model.d.ts +51 -0
- package/dist/src/model.js +243 -0
- package/dist/src/relationships.d.ts +18 -0
- package/dist/src/relationships.js +50 -0
- package/package.json +15 -3
- package/.env.example +0 -9
- package/.eslintrc.json +0 -36
- package/.gitattributes +0 -8
- package/CODE_OF_CONDUCT.md +0 -76
- package/changelog.md +0 -135
- package/index.ts +0 -31
- package/initDb.ts +0 -112
- package/knexfile.ts +0 -46
- package/pnpm-workspace.yaml +0 -9
- package/scripts/migrate.ts +0 -97
- package/src/config.ts +0 -270
- package/src/model.ts +0 -301
- package/src/relationships.ts +0 -93
- package/tsconfig.json +0 -27
- package/types/pluralize.d.ts +0 -4
package/.eslintrc.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"commonjs": true,
|
|
4
|
-
"es2021": true,
|
|
5
|
-
"node": true
|
|
6
|
-
},
|
|
7
|
-
"extends": "eslint:recommended",
|
|
8
|
-
"plugins": ["@babel"],
|
|
9
|
-
"parser": "@babel/eslint-parser",
|
|
10
|
-
"parserOptions": {
|
|
11
|
-
"ecmaVersion": 12
|
|
12
|
-
},
|
|
13
|
-
"rules": {
|
|
14
|
-
"no-console":"warn",
|
|
15
|
-
"constructor-super":"off",
|
|
16
|
-
"no-this-before-super":"off",
|
|
17
|
-
"arrow-parens":"error",
|
|
18
|
-
"class-methods-use-this":"error",
|
|
19
|
-
"indent": [
|
|
20
|
-
"error",
|
|
21
|
-
"tab"
|
|
22
|
-
],
|
|
23
|
-
"linebreak-style": [
|
|
24
|
-
"error",
|
|
25
|
-
"unix"
|
|
26
|
-
],
|
|
27
|
-
"quotes": [
|
|
28
|
-
"error",
|
|
29
|
-
"single"
|
|
30
|
-
],
|
|
31
|
-
"semi": [
|
|
32
|
-
"error",
|
|
33
|
-
"never"
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
}
|
package/.gitattributes
DELETED
package/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
-
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
|
9
|
-
level of experience, education, socio-economic status, nationality, personal
|
|
10
|
-
appearance, race, religion, or sexual identity and orientation.
|
|
11
|
-
|
|
12
|
-
## Our Standards
|
|
13
|
-
|
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
|
15
|
-
include:
|
|
16
|
-
|
|
17
|
-
* Using welcoming and inclusive language
|
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
|
19
|
-
* Gracefully accepting constructive criticism
|
|
20
|
-
* Focusing on what is best for the community
|
|
21
|
-
* Showing empathy towards other community members
|
|
22
|
-
|
|
23
|
-
Examples of unacceptable behavior by participants include:
|
|
24
|
-
|
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
-
advances
|
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
-
* Public or private harassment
|
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
|
30
|
-
address, without explicit permission
|
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
-
professional setting
|
|
33
|
-
|
|
34
|
-
## Our Responsibilities
|
|
35
|
-
|
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
-
response to any instances of unacceptable behavior.
|
|
39
|
-
|
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
-
threatening, offensive, or harmful.
|
|
45
|
-
|
|
46
|
-
## Scope
|
|
47
|
-
|
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
-
when an individual is representing the project or its community. Examples of
|
|
50
|
-
representing a project or community include using an official project e-mail
|
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
|
53
|
-
further defined and clarified by project maintainers.
|
|
54
|
-
|
|
55
|
-
## Enforcement
|
|
56
|
-
|
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
-
reported by contacting the project team at stanleyoren@gmail.com. All
|
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
|
63
|
-
|
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
-
members of the project's leadership.
|
|
67
|
-
|
|
68
|
-
## Attribution
|
|
69
|
-
|
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
-
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
|
72
|
-
|
|
73
|
-
[homepage]: https://www.contributor-covenant.org
|
|
74
|
-
|
|
75
|
-
For answers to common questions about this code of conduct, see
|
|
76
|
-
https://www.contributor-covenant.org/faq
|
package/changelog.md
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
## [unreleased]
|
|
2
|
-
|
|
3
|
-
### 💼 Other
|
|
4
|
-
|
|
5
|
-
- Use Node 16 until I figure out what is going on
|
|
6
|
-
## [3.2.0] - 2025-09-29
|
|
7
|
-
|
|
8
|
-
### 🐛 Bug Fixes
|
|
9
|
-
|
|
10
|
-
- *(deps)* Bump actions/checkout from 4 to 5
|
|
11
|
-
- *(deps)* Bump actions/setup-node from 4 to 5
|
|
12
|
-
|
|
13
|
-
### 💼 Other
|
|
14
|
-
|
|
15
|
-
- Support the latest versions of node
|
|
16
|
-
- Only use Node 20 for tests
|
|
17
|
-
|
|
18
|
-
### ⚙️ Miscellaneous Tasks
|
|
19
|
-
|
|
20
|
-
- Upgrade deps
|
|
21
|
-
## [3.0.0] - 2025-07-02
|
|
22
|
-
|
|
23
|
-
### 🐛 Bug Fixes
|
|
24
|
-
|
|
25
|
-
- *(deps)* Bump actions/checkout from 3 to 4
|
|
26
|
-
- *(deps)* Bump actions/setup-node from 3 to 4
|
|
27
|
-
|
|
28
|
-
### ⚙️ Miscellaneous Tasks
|
|
29
|
-
|
|
30
|
-
- Upgrade deps
|
|
31
|
-
## [2.4.7-1] - 2023-03-08
|
|
32
|
-
|
|
33
|
-
### ⚙️ Miscellaneous Tasks
|
|
34
|
-
|
|
35
|
-
- Update the default peer dep
|
|
36
|
-
## [2.4.6] - 2023-03-08
|
|
37
|
-
|
|
38
|
-
### ⚙️ Miscellaneous Tasks
|
|
39
|
-
|
|
40
|
-
- Add auto publish to npm
|
|
41
|
-
## [2.4.5] - 2023-03-06
|
|
42
|
-
|
|
43
|
-
### 💼 Other
|
|
44
|
-
|
|
45
|
-
- Update npm dependencies
|
|
46
|
-
|
|
47
|
-
### ⚙️ Miscellaneous Tasks
|
|
48
|
-
|
|
49
|
-
- *(ci)* Drop support for node 14
|
|
50
|
-
- *(version)* Release patch version 2.4.5
|
|
51
|
-
## [2.4.4] - 2023-01-04
|
|
52
|
-
|
|
53
|
-
### ⚙️ Miscellaneous Tasks
|
|
54
|
-
|
|
55
|
-
- *(version)* Release patch version 2.4.4
|
|
56
|
-
## [2.4.3] - 2023-01-04
|
|
57
|
-
|
|
58
|
-
### ⚙️ Miscellaneous Tasks
|
|
59
|
-
|
|
60
|
-
- *(version)* Release patch version 2.4.3
|
|
61
|
-
## [2.4.2] - 2023-01-03
|
|
62
|
-
|
|
63
|
-
### 🐛 Bug Fixes
|
|
64
|
-
|
|
65
|
-
- *(deps)* Bump actions/checkout from 2 to 3 (#60)
|
|
66
|
-
|
|
67
|
-
### ⚙️ Miscellaneous Tasks
|
|
68
|
-
|
|
69
|
-
- *(version)* Release patch version 2.4.2
|
|
70
|
-
## [2.4.1] - 2022-07-21
|
|
71
|
-
|
|
72
|
-
### ⚙️ Miscellaneous Tasks
|
|
73
|
-
|
|
74
|
-
- *(version)* Release patch version 2.4.1
|
|
75
|
-
## [2.4.0] - 2022-07-20
|
|
76
|
-
|
|
77
|
-
### ⚙️ Miscellaneous Tasks
|
|
78
|
-
|
|
79
|
-
- *(version)* Release minor version 2.4.0
|
|
80
|
-
## [2.3.7] - 2022-07-20
|
|
81
|
-
|
|
82
|
-
### 🐛 Bug Fixes
|
|
83
|
-
|
|
84
|
-
- *(deps)* Bump actions/setup-node from 2 to 3 (#59)
|
|
85
|
-
- *(dev)* Throwing error in the init db command that is used for setup
|
|
86
|
-
|
|
87
|
-
### ⚙️ Miscellaneous Tasks
|
|
88
|
-
|
|
89
|
-
- *(dev)* The default database in .env.example is now mysql
|
|
90
|
-
- *(dev)* Using sqlite 3 instead of @vscode/sqlite3
|
|
91
|
-
- *(version)* Release patch version 2.3.7
|
|
92
|
-
## [2.3.6] - 2022-02-03
|
|
93
|
-
|
|
94
|
-
### 🐛 Bug Fixes
|
|
95
|
-
|
|
96
|
-
- *(config)* Error when reolving config from the user defined config. file not found
|
|
97
|
-
- *(knexfile)* The path of the knex file was still not updated to use either of the 2 .js or .cjs
|
|
98
|
-
|
|
99
|
-
### ⚙️ Miscellaneous Tasks
|
|
100
|
-
|
|
101
|
-
- *(version)* Release patch version 2.3.2
|
|
102
|
-
- *(version)* Release patch version 2.3.3
|
|
103
|
-
- *(version)* Release patch version 2.3.4
|
|
104
|
-
- *(version)* Release patch version 2.3.5
|
|
105
|
-
- *(version)* Release patch version 2.3.6
|
|
106
|
-
## [2.3.1] - 2022-02-01
|
|
107
|
-
|
|
108
|
-
### ⚙️ Miscellaneous Tasks
|
|
109
|
-
|
|
110
|
-
- *(version)* Release minor version 2.3.1
|
|
111
|
-
## [2.3.0] - 2022-02-01
|
|
112
|
-
|
|
113
|
-
### 🚀 Features
|
|
114
|
-
|
|
115
|
-
- *(find)* Added the static find method
|
|
116
|
-
- *(model)* Added the create method
|
|
117
|
-
- *(update)* Added the instance update method
|
|
118
|
-
- *(delete)* Added a delete method
|
|
119
|
-
|
|
120
|
-
### 🐛 Bug Fixes
|
|
121
|
-
|
|
122
|
-
- *(deps)* Bump knex from 0.21.17 to 0.95.11 (#12)
|
|
123
|
-
- *(exports)* Breaking changes were pushed with the previous change. the changes has been fixed
|
|
124
|
-
- *(tableName)* Not hiding the table by default
|
|
125
|
-
- *(first)* Fixed the first method
|
|
126
|
-
- *(knexfile)* Loading knexfile from the current working dir instead of the root of the package
|
|
127
|
-
- *(deps)* The latest knex version removed as a peer dep.
|
|
128
|
-
|
|
129
|
-
### ⚙️ Miscellaneous Tasks
|
|
130
|
-
|
|
131
|
-
- *(package)* Updated package.json
|
|
132
|
-
- *(es6)* Using .cjs for knexfile
|
|
133
|
-
- *(version)* Release 2.2.13
|
|
134
|
-
- *(version)* Release minor version 2.2.14
|
|
135
|
-
- *(version)* Release minor version 2.3.0
|
package/index.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Model,
|
|
3
|
-
DB,
|
|
4
|
-
getDB,
|
|
5
|
-
configure,
|
|
6
|
-
createKnexConfig,
|
|
7
|
-
configureDatabase,
|
|
8
|
-
setMigrationConfig,
|
|
9
|
-
getMigrationConfig,
|
|
10
|
-
makeMigration,
|
|
11
|
-
migrateLatest,
|
|
12
|
-
migrateRollback,
|
|
13
|
-
migrateCurrentVersion,
|
|
14
|
-
migrateList,
|
|
15
|
-
} from './src/model.js'
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
Model,
|
|
19
|
-
DB,
|
|
20
|
-
getDB,
|
|
21
|
-
configure,
|
|
22
|
-
createKnexConfig,
|
|
23
|
-
configureDatabase,
|
|
24
|
-
setMigrationConfig,
|
|
25
|
-
getMigrationConfig,
|
|
26
|
-
makeMigration,
|
|
27
|
-
migrateLatest,
|
|
28
|
-
migrateRollback,
|
|
29
|
-
migrateCurrentVersion,
|
|
30
|
-
migrateList,
|
|
31
|
-
}
|
package/initDb.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { existsSync } from 'node:fs'
|
|
3
|
-
import { pathToFileURL } from 'node:url'
|
|
4
|
-
import 'dotenv/config'
|
|
5
|
-
import type { Knex } from 'knex'
|
|
6
|
-
import knexModule from 'knex'
|
|
7
|
-
|
|
8
|
-
interface KnexEnvConfig {
|
|
9
|
-
development: Knex.Config
|
|
10
|
-
staging: Knex.Config
|
|
11
|
-
production: Knex.Config
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type KnexFactory = (config: Knex.Config) => Knex
|
|
15
|
-
|
|
16
|
-
const KnexFactoryImpl: KnexFactory =
|
|
17
|
-
(knexModule as unknown as { knex?: KnexFactory }).knex ??
|
|
18
|
-
(knexModule as unknown as KnexFactory)
|
|
19
|
-
|
|
20
|
-
const knexfilePath = `${process.cwd()}/knexfile.ts`
|
|
21
|
-
if (!existsSync(knexfilePath)) {
|
|
22
|
-
throw new Error('knexfile.ts not found in current working directory')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const knexConfigModule = await import(pathToFileURL(knexfilePath).href)
|
|
26
|
-
const knexConfig = (knexConfigModule.default ?? knexConfigModule) as Partial<KnexEnvConfig>
|
|
27
|
-
const { development, staging, production } = knexConfig
|
|
28
|
-
|
|
29
|
-
if (!development || !staging || !production) {
|
|
30
|
-
throw new Error('knexfile.ts must export development, staging, and production config')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const config: Knex.Config = (() => {
|
|
34
|
-
switch (process.env.NODE_ENV) {
|
|
35
|
-
case 'testing':
|
|
36
|
-
case 'test':
|
|
37
|
-
case 'development':
|
|
38
|
-
return development
|
|
39
|
-
case 'staging':
|
|
40
|
-
return staging
|
|
41
|
-
default:
|
|
42
|
-
return production
|
|
43
|
-
}
|
|
44
|
-
})()
|
|
45
|
-
|
|
46
|
-
const initDatabase = async (): Promise<void> => {
|
|
47
|
-
const DB = KnexFactoryImpl(config)
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
await DB.schema.dropTableIfExists('farmers')
|
|
51
|
-
await DB.schema.dropTableIfExists('farms')
|
|
52
|
-
await DB.schema.dropTableIfExists('profiles')
|
|
53
|
-
await DB.schema.dropTableIfExists('articles')
|
|
54
|
-
|
|
55
|
-
await DB.schema.createTable('farmers', (table: Knex.CreateTableBuilder) => {
|
|
56
|
-
table.bigIncrements('id')
|
|
57
|
-
table.string('name')
|
|
58
|
-
table.string('email').unique()
|
|
59
|
-
table.string('password')
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
await DB.schema.createTable('farms', (table: Knex.CreateTableBuilder) => {
|
|
63
|
-
table.bigIncrements('id')
|
|
64
|
-
table.bigInteger('farmer_id')
|
|
65
|
-
table.string('name')
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
await DB.schema.createTable('profiles', (table: Knex.CreateTableBuilder) => {
|
|
69
|
-
table.bigIncrements('id')
|
|
70
|
-
table.bigInteger('farmer_id')
|
|
71
|
-
table.string('bio')
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
await DB.schema.createTable('articles', (table: Knex.CreateTableBuilder) => {
|
|
75
|
-
table.bigIncrements('id')
|
|
76
|
-
table.string('title')
|
|
77
|
-
table.text('body')
|
|
78
|
-
table.bigInteger('postable_id')
|
|
79
|
-
table.string('postable_type')
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
await DB.table('Farmers').insert([
|
|
83
|
-
{ name: 'Jane Doe', email: 'jane@mail.com', password: 'pasword' },
|
|
84
|
-
{ name: 'Ashley Doe', email: 'ashley@mail.com', password: 'pasword' },
|
|
85
|
-
{ name: 'Alice Doe', email: 'alice@mail.com', password: 'pasword' },
|
|
86
|
-
])
|
|
87
|
-
|
|
88
|
-
await DB.table('farms').insert([
|
|
89
|
-
{ farmer_id: 1, name: 'Awesome Farm' },
|
|
90
|
-
{ farmer_id: 1, name: 'Awesome Farm two' },
|
|
91
|
-
{ farmer_id: 1, name: 'Awesome Farm three' },
|
|
92
|
-
])
|
|
93
|
-
|
|
94
|
-
await DB.table('profiles').insert([{ farmer_id: 1, bio: 'Profile for farmer one' }])
|
|
95
|
-
|
|
96
|
-
await DB.table('articles').insert([
|
|
97
|
-
{
|
|
98
|
-
title: 'Awesome Post',
|
|
99
|
-
body: 'fffgjdfjdbdb something #1',
|
|
100
|
-
postable_id: 1,
|
|
101
|
-
postable_type: 'Farmer',
|
|
102
|
-
},
|
|
103
|
-
])
|
|
104
|
-
|
|
105
|
-
process.exit(0)
|
|
106
|
-
} catch (error: unknown) {
|
|
107
|
-
console.error(error)
|
|
108
|
-
process.exit(1)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
await initDatabase()
|
package/knexfile.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { Knex } from 'knex'
|
|
2
|
-
|
|
3
|
-
const config = {
|
|
4
|
-
development: {
|
|
5
|
-
client: 'sqlite3',
|
|
6
|
-
connection: {
|
|
7
|
-
filename: './dev.sqlite',
|
|
8
|
-
},
|
|
9
|
-
useNullAsDefault: true,
|
|
10
|
-
migrations: {
|
|
11
|
-
tableName: 'migrations',
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
staging: {
|
|
15
|
-
client: process.env.DB_CLIENT ?? 'mysql2',
|
|
16
|
-
connection: {
|
|
17
|
-
database: process.env.DB_DATABASE ?? 'my_db',
|
|
18
|
-
user: process.env.DB_USER ?? 'username',
|
|
19
|
-
password: process.env.DB_PASSWORD ?? 'password',
|
|
20
|
-
},
|
|
21
|
-
pool: {
|
|
22
|
-
min: 2,
|
|
23
|
-
max: 10,
|
|
24
|
-
},
|
|
25
|
-
migrations: {
|
|
26
|
-
tableName: 'migrations',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
production: {
|
|
30
|
-
client: process.env.DB_CLIENT ?? 'mysql2',
|
|
31
|
-
connection: {
|
|
32
|
-
database: process.env.DB_DATABASE ?? 'my_db',
|
|
33
|
-
user: process.env.DB_USER ?? 'username',
|
|
34
|
-
password: process.env.DB_PASSWORD ?? 'password',
|
|
35
|
-
},
|
|
36
|
-
pool: {
|
|
37
|
-
min: 2,
|
|
38
|
-
max: 10,
|
|
39
|
-
},
|
|
40
|
-
migrations: {
|
|
41
|
-
tableName: 'migrations',
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
} satisfies Record<'development' | 'staging' | 'production', Knex.Config>
|
|
45
|
-
|
|
46
|
-
export default config
|
package/pnpm-workspace.yaml
DELETED
package/scripts/migrate.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
configureDatabase,
|
|
4
|
-
setMigrationConfig,
|
|
5
|
-
makeMigration,
|
|
6
|
-
migrateLatest,
|
|
7
|
-
migrateRollback,
|
|
8
|
-
migrateList,
|
|
9
|
-
migrateCurrentVersion,
|
|
10
|
-
} from '../index.js'
|
|
11
|
-
|
|
12
|
-
const [command = 'latest', name] = process.argv.slice(2)
|
|
13
|
-
|
|
14
|
-
const databaseConfig: Parameters<typeof configureDatabase>[0] = {
|
|
15
|
-
dialect: (process.env.DB_DIALECT as
|
|
16
|
-
| 'sqlite'
|
|
17
|
-
| 'better-sqlite3'
|
|
18
|
-
| 'mysql'
|
|
19
|
-
| 'mysql2'
|
|
20
|
-
| 'postgres'
|
|
21
|
-
| 'postgresql'
|
|
22
|
-
| 'pg'
|
|
23
|
-
| 'pgnative'
|
|
24
|
-
| 'cockroachdb'
|
|
25
|
-
| 'redshift'
|
|
26
|
-
| 'mssql'
|
|
27
|
-
| 'oracledb'
|
|
28
|
-
| 'oracle') ?? 'sqlite',
|
|
29
|
-
filename: process.env.DB_FILENAME ?? './dev.sqlite',
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (process.env.DATABASE_URL) {
|
|
33
|
-
databaseConfig.connectionString = process.env.DATABASE_URL
|
|
34
|
-
}
|
|
35
|
-
if (process.env.DB_HOST) {
|
|
36
|
-
databaseConfig.host = process.env.DB_HOST
|
|
37
|
-
}
|
|
38
|
-
if (process.env.DB_PORT) {
|
|
39
|
-
databaseConfig.port = Number(process.env.DB_PORT)
|
|
40
|
-
}
|
|
41
|
-
if (process.env.DB_USER) {
|
|
42
|
-
databaseConfig.user = process.env.DB_USER
|
|
43
|
-
}
|
|
44
|
-
if (process.env.DB_PASSWORD) {
|
|
45
|
-
databaseConfig.password = process.env.DB_PASSWORD
|
|
46
|
-
}
|
|
47
|
-
if (process.env.DB_NAME) {
|
|
48
|
-
databaseConfig.database = process.env.DB_NAME
|
|
49
|
-
}
|
|
50
|
-
if (process.env.DB_SSL === 'true') {
|
|
51
|
-
databaseConfig.ssl = true
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
configureDatabase(databaseConfig)
|
|
55
|
-
|
|
56
|
-
setMigrationConfig({
|
|
57
|
-
directory: process.env.MIGRATIONS_DIR ?? './migrations',
|
|
58
|
-
extension: process.env.MIGRATIONS_EXT ?? 'ts',
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const run = async (): Promise<void> => {
|
|
62
|
-
switch (command) {
|
|
63
|
-
case 'make': {
|
|
64
|
-
if (!name) {
|
|
65
|
-
throw new Error('Usage: node --import tsx scripts/migrate.ts make <name>')
|
|
66
|
-
}
|
|
67
|
-
const file = await makeMigration(name)
|
|
68
|
-
console.log(file)
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
case 'latest': {
|
|
72
|
-
const result = await migrateLatest()
|
|
73
|
-
console.log(JSON.stringify(result, null, 2))
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
case 'rollback': {
|
|
77
|
-
const all = process.argv.includes('--all')
|
|
78
|
-
const result = await migrateRollback(undefined, all)
|
|
79
|
-
console.log(JSON.stringify(result, null, 2))
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
case 'list': {
|
|
83
|
-
const result = await migrateList()
|
|
84
|
-
console.log(JSON.stringify(result, null, 2))
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
case 'version': {
|
|
88
|
-
const version = await migrateCurrentVersion()
|
|
89
|
-
console.log(version)
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
default:
|
|
93
|
-
throw new Error(`Unknown command "${command}". Use make|latest|rollback|list|version`)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
await run()
|