@platformatic/db 3.4.1 → 3.5.0
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/README.md +1 -1
- package/config.d.ts +442 -107
- package/eslint.config.js +9 -5
- package/index.d.ts +53 -31
- package/index.js +30 -139
- package/lib/application.js +102 -0
- package/lib/capability.js +35 -0
- package/lib/commands/index.js +59 -0
- package/lib/commands/migrations-apply.js +63 -0
- package/lib/commands/migrations-create.js +48 -0
- package/lib/commands/print-schema.js +31 -0
- package/lib/commands/seed.js +74 -0
- package/lib/commands/types.js +22 -0
- package/lib/config.js +52 -0
- package/lib/errors.js +16 -12
- package/lib/generator.js +229 -0
- package/lib/{migrator.mjs → migrator.js} +46 -38
- package/lib/{root-endpoint/index.js → root.js} +6 -7
- package/lib/schema.js +41 -20
- package/lib/{generator/code-templates.js → templates.js} +57 -16
- package/lib/types.js +161 -0
- package/lib/upgrade.js +8 -12
- package/lib/utils.js +12 -23
- package/lib/versions/0.18.0.js +3 -5
- package/lib/versions/{from-zero-twenty-height-to-will-see.js → 0.28.0.js} +3 -5
- package/lib/versions/2.0.0.js +3 -5
- package/lib/versions/3.0.0.js +14 -0
- package/package.json +32 -40
- package/schema.json +1385 -164
- package/tsconfig.json +16 -6
- package/db.mjs +0 -86
- package/help/compile.txt +0 -17
- package/help/create.txt +0 -13
- package/help/help.txt +0 -11
- package/help/migrations apply.txt +0 -45
- package/help/migrations create.txt +0 -27
- package/help/migrations.txt +0 -4
- package/help/schema.txt +0 -25
- package/help/seed.txt +0 -36
- package/help/start.txt +0 -47
- package/help/types.txt +0 -40
- package/index.test-d.ts +0 -43
- package/lib/adjust-config.js +0 -42
- package/lib/create.mjs +0 -89
- package/lib/gen-migration.mjs +0 -53
- package/lib/gen-schema.mjs +0 -68
- package/lib/gen-types.mjs +0 -202
- package/lib/generator/README.md +0 -38
- package/lib/generator/db-generator.js +0 -260
- package/lib/generator.d.ts +0 -7
- package/lib/migrate.mjs +0 -81
- package/lib/seed.mjs +0 -90
- package/lib/stackable.js +0 -49
- /package/{lib/root-endpoint/public → public}/images/dark_mode.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/favicon.ico +0 -0
- /package/{lib/root-endpoint/public → public}/images/light_mode.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/platformatic-logo-dark.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/platformatic-logo-light.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/triangle_dark.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/triangle_light.svg +0 -0
- /package/{lib/root-endpoint/public → public}/index.html +0 -0
package/lib/seed.mjs
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import pino from 'pino'
|
|
2
|
-
import pretty from 'pino-pretty'
|
|
3
|
-
import { access, readFile } from 'fs/promises'
|
|
4
|
-
import { setupDB } from './utils.js'
|
|
5
|
-
import { Migrator } from './migrator.mjs'
|
|
6
|
-
import { pathToFileURL } from 'url'
|
|
7
|
-
import { loadConfig } from '@platformatic/config'
|
|
8
|
-
import { platformaticDB } from '../index.js'
|
|
9
|
-
import errors from './errors.js'
|
|
10
|
-
import tsCompiler from '@platformatic/ts-compiler'
|
|
11
|
-
import { join, resolve } from 'node:path'
|
|
12
|
-
|
|
13
|
-
async function execute (logger, seedFile, config) {
|
|
14
|
-
const { db, sql, entities } = await setupDB(logger, config.db)
|
|
15
|
-
|
|
16
|
-
await access(seedFile)
|
|
17
|
-
|
|
18
|
-
logger.info(`seeding from ${seedFile}`)
|
|
19
|
-
let seedFunction
|
|
20
|
-
const importedFunction = await import(pathToFileURL(seedFile))
|
|
21
|
-
|
|
22
|
-
if (typeof importedFunction === 'function') {
|
|
23
|
-
seedFunction = importedFunction
|
|
24
|
-
} else if (typeof importedFunction.seed === 'function') {
|
|
25
|
-
seedFunction = importedFunction.seed
|
|
26
|
-
} else if (typeof importedFunction.default === 'function') {
|
|
27
|
-
seedFunction = importedFunction.default
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!seedFunction) {
|
|
31
|
-
logger.error('Cannot find seed function.')
|
|
32
|
-
logger.error('If you use an ESM module use the signature \'export async function seed (opts)\'.')
|
|
33
|
-
logger.error('If you use a CJS module use the signature \'module.exports = async function seed (opts)\'.')
|
|
34
|
-
logger.error('If you use Typescript use the signature \'export async function seed(opts)\'')
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
await seedFunction({ db, sql, entities, logger })
|
|
38
|
-
logger.info('seeding complete')
|
|
39
|
-
|
|
40
|
-
// Once done seeding, close your connection.
|
|
41
|
-
await db.dispose()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function seed (_args) {
|
|
45
|
-
const logger = pino(pretty({
|
|
46
|
-
translateTime: 'SYS:HH:MM:ss',
|
|
47
|
-
ignore: 'hostname,pid',
|
|
48
|
-
}))
|
|
49
|
-
|
|
50
|
-
const { configManager, args } = await loadConfig({
|
|
51
|
-
alias: {
|
|
52
|
-
c: 'config',
|
|
53
|
-
},
|
|
54
|
-
}, _args, platformaticDB)
|
|
55
|
-
await configManager.parseAndValidate()
|
|
56
|
-
const config = configManager.current
|
|
57
|
-
|
|
58
|
-
if (config.migrations !== undefined) {
|
|
59
|
-
const migrator = new Migrator(config.migrations, config.db, logger)
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const hasMigrationsToApply = await migrator.hasMigrationsToApply()
|
|
63
|
-
if (hasMigrationsToApply) {
|
|
64
|
-
throw new errors.MigrationsToApplyError()
|
|
65
|
-
}
|
|
66
|
-
} finally {
|
|
67
|
-
await migrator.close()
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
let seedFile = args._[0]
|
|
71
|
-
if (!seedFile) {
|
|
72
|
-
throw new errors.MissingSeedFileError()
|
|
73
|
-
}
|
|
74
|
-
// check if we are in Typescript and, in case, compile it
|
|
75
|
-
if (seedFile.endsWith('.ts')) {
|
|
76
|
-
await tsCompiler.compile({
|
|
77
|
-
cwd: process.cwd(),
|
|
78
|
-
logger,
|
|
79
|
-
tsConfig: configManager.current.plugins?.typescript?.tsConfig,
|
|
80
|
-
flags: configManager.current.plugins?.typescript?.flags,
|
|
81
|
-
})
|
|
82
|
-
const tsConfigPath = config?.plugins?.typescript?.tsConfig || resolve(process.cwd(), 'tsconfig.json')
|
|
83
|
-
const tsConfig = JSON.parse(await readFile(tsConfigPath, 'utf8'))
|
|
84
|
-
const outDir = tsConfig.compilerOptions.outDir
|
|
85
|
-
seedFile = join(outDir, seedFile.replace('.ts', '.js'))
|
|
86
|
-
}
|
|
87
|
-
await execute(logger, seedFile, config)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export { seed, execute }
|
package/lib/stackable.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { ServiceStackable } = require('@platformatic/service')
|
|
4
|
-
|
|
5
|
-
class DbStackable extends ServiceStackable {
|
|
6
|
-
constructor (options) {
|
|
7
|
-
super(options)
|
|
8
|
-
this.#updateConfig()
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
#updateConfig () {
|
|
12
|
-
if (!this.context) return
|
|
13
|
-
|
|
14
|
-
const { isProduction } = this.context
|
|
15
|
-
const config = this.configManager.current
|
|
16
|
-
|
|
17
|
-
if (isProduction) {
|
|
18
|
-
if (config.autogenerate) {
|
|
19
|
-
config.autogenerate = false
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this.configManager.update(config)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async getMeta () {
|
|
27
|
-
await this.init()
|
|
28
|
-
await this.app.ready()
|
|
29
|
-
|
|
30
|
-
const serviceMeta = await super.getMeta()
|
|
31
|
-
|
|
32
|
-
const config = this.configManager.current
|
|
33
|
-
|
|
34
|
-
const dbConfig = config.db
|
|
35
|
-
const connectionString = dbConfig?.connectionString
|
|
36
|
-
|
|
37
|
-
if (connectionString) {
|
|
38
|
-
return {
|
|
39
|
-
...serviceMeta,
|
|
40
|
-
db: {
|
|
41
|
-
connectionStrings: [connectionString]
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return serviceMeta
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
module.exports = { DbStackable }
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|