@platformatic/db 2.71.1-alpha.0 → 3.0.0-alpha.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/config.d.ts +1 -19
- package/eslint.config.js +9 -5
- package/index.d.ts +56 -31
- package/index.js +67 -128
- package/lib/application.js +102 -0
- package/lib/commands/index.js +59 -0
- package/lib/commands/migrations-apply.js +62 -0
- package/lib/commands/migrations-create.js +48 -0
- package/lib/commands/print-schema.js +30 -0
- package/lib/commands/seed.js +88 -0
- package/lib/commands/types.js +21 -0
- package/lib/errors.js +15 -11
- package/lib/{generator/db-generator.js → generator.js} +57 -52
- package/lib/{migrator.mjs → migrator.js} +45 -37
- package/lib/{root-endpoint/index.js → root.js} +6 -7
- package/lib/schema.js +31 -21
- package/lib/stackable.js +14 -26
- package/lib/{generator/code-templates.js → templates.js} +47 -17
- package/lib/types.js +160 -0
- package/lib/upgrade.js +7 -10
- 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/package.json +16 -23
- package/schema.json +2 -73
- package/tsconfig.json +16 -6
- package/.snapshots/810d795d512560f3863d8db472c81c27/0.json +0 -1
- package/.snapshots/810d795d512560f3863d8db472c81c27/1.json +0 -1
- 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.d.ts +0 -7
- package/lib/migrate.mjs +0 -87
- package/lib/seed.mjs +0 -90
- /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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"{\n \"openapi\": \"3.0.3\",\n \"info\": {\n \"title\": \"Platformatic DB\",\n \"description\": \"Exposing a SQL database as REST\",\n \"version\": \"1.0.0\"\n },\n \"components\": {\n \"schemas\": {\n \"Graph\": {\n \"title\": \"Graph\",\n \"description\": \"A Graph\",\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"nullable\": true\n },\n \"name\": {\n \"type\": \"string\",\n \"nullable\": true\n }\n },\n \"additionalProperties\": false\n },\n \"GraphInput\": {\n \"title\": \"GraphInput\",\n \"description\": \"A Graph\",\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": \"integer\"\n },\n \"name\": {\n \"type\": \"string\",\n \"nullable\": true\n }\n },\n \"additionalProperties\": false\n }\n }\n },\n \"paths\": {\n \"/graphs/\": {\n \"get\": {\n \"operationId\": \"getGraphs\",\n \"summary\": \"Get graphs.\",\n \"tags\": [\n \"graphs\"\n ],\n \"description\": \"Fetch graphs from the database.\",\n \"parameters\": [\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"limit\",\n \"required\": false,\n \"description\": \"Limit will be applied by default if not passed. If the provided value exceeds the maximum allowed value a validation error will be thrown\"\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"offset\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"boolean\",\n \"default\": false\n },\n \"in\": \"query\",\n \"name\": \"totalCount\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"boolean\",\n \"default\": false\n },\n \"in\": \"query\",\n \"name\": \"cursor\",\n \"required\": false,\n \"description\": \"Include cursor headers in response. Cursor keys built from orderBy clause\"\n },\n {\n \"schema\": {\n \"type\": \"string\",\n \"format\": \"byte\"\n },\n \"in\": \"query\",\n \"name\": \"startAfter\",\n \"required\": false,\n \"description\": \"Cursor for forward pagination. List objects after this cursor position\"\n },\n {\n \"schema\": {\n \"type\": \"string\",\n \"format\": \"byte\"\n },\n \"in\": \"query\",\n \"name\": \"endBefore\",\n \"required\": false,\n \"description\": \"Cursor for backward pagination. List objects before this cursor position\"\n },\n {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\",\n \"enum\": [\n \"id\",\n \"name\"\n ]\n }\n },\n \"in\": \"query\",\n \"name\": \"fields\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.eq\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.neq\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.gt\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.gte\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.lt\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.lte\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.like\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.ilike\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.in\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.nin\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.contains\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.contained\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.overlaps\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.eq\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.neq\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.gt\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.gte\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.lt\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.lte\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.like\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.ilike\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.in\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.nin\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.contains\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.contained\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.overlaps\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n },\n \"in\": \"query\",\n \"name\": \"where.or\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\",\n \"enum\": [\n \"asc\",\n \"desc\"\n ]\n },\n \"in\": \"query\",\n \"name\": \"orderby.id\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\",\n \"enum\": [\n \"asc\",\n \"desc\"\n ]\n },\n \"in\": \"query\",\n \"name\": \"orderby.name\",\n \"required\": false\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Default Response\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"$ref\": \"#/components/schemas/Graph\"\n }\n }\n }\n }\n }\n }\n },\n \"post\": {\n \"operationId\": \"createGraph\",\n \"summary\": \"Create graph.\",\n \"tags\": [\n \"graphs\"\n ],\n \"description\": \"Add new graph to the database.\",\n \"requestBody\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/GraphInput\"\n }\n }\n }\n },\n \"responses\": {\n \"200\": {\n \"description\": \"A Graph\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/Graph\"\n }\n }\n },\n \"links\": {}\n }\n }\n },\n \"put\": {\n \"operationId\": \"updateGraphs\",\n \"summary\": \"Update graphs.\",\n \"tags\": [\n \"graphs\"\n ],\n \"description\": \"Update one or more graphs in the database.\",\n \"requestBody\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/GraphInput\"\n }\n }\n }\n },\n \"parameters\": [\n {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\",\n \"enum\": [\n \"id\",\n \"name\"\n ]\n }\n },\n \"in\": \"query\",\n \"name\": \"fields\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.eq\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.neq\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.gt\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.gte\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.lt\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.lte\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.like\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.ilike\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.in\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.nin\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.contains\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.contained\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.id.overlaps\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.eq\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.neq\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.gt\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.gte\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.lt\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.lte\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.like\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.ilike\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.in\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.nin\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.contains\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.contained\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"string\"\n },\n \"in\": \"query\",\n \"name\": \"where.name.overlaps\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n },\n \"in\": \"query\",\n \"name\": \"where.or\",\n \"required\": false\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Default Response\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"$ref\": \"#/components/schemas/Graph\"\n }\n }\n }\n },\n \"links\": {}\n }\n }\n }\n },\n \"/graphs/{id}\": {\n \"get\": {\n \"operationId\": \"getGraphById\",\n \"summary\": \"Get Graph by id.\",\n \"tags\": [\n \"graphs\"\n ],\n \"description\": \"Fetch Graph using its id from the database.\",\n \"parameters\": [\n {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\",\n \"enum\": [\n \"id\",\n \"name\"\n ]\n }\n },\n \"in\": \"query\",\n \"name\": \"fields\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"path\",\n \"name\": \"id\",\n \"required\": true\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"A Graph\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/Graph\"\n }\n }\n },\n \"links\": {}\n }\n }\n },\n \"put\": {\n \"operationId\": \"updateGraph\",\n \"summary\": \"Update graph.\",\n \"tags\": [\n \"graphs\"\n ],\n \"description\": \"Update graph in the database.\",\n \"requestBody\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/GraphInput\"\n }\n }\n }\n },\n \"parameters\": [\n {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\",\n \"enum\": [\n \"id\",\n \"name\"\n ]\n }\n },\n \"in\": \"query\",\n \"name\": \"fields\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"path\",\n \"name\": \"id\",\n \"required\": true\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"A Graph\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/Graph\"\n }\n }\n },\n \"links\": {}\n }\n }\n },\n \"delete\": {\n \"operationId\": \"deleteGraphs\",\n \"summary\": \"Delete graphs.\",\n \"tags\": [\n \"graphs\"\n ],\n \"description\": \"Delete one or more graphs from the Database.\",\n \"parameters\": [\n {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\",\n \"enum\": [\n \"id\",\n \"name\"\n ]\n }\n },\n \"in\": \"query\",\n \"name\": \"fields\",\n \"required\": false\n },\n {\n \"schema\": {\n \"type\": \"integer\"\n },\n \"in\": \"path\",\n \"name\": \"id\",\n \"required\": true\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"A Graph\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/Graph\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"servers\": [\n {\n \"url\": \"/\"\n }\n ]\n}"
|
package/db.mjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import commist from 'commist'
|
|
4
|
-
import parseArgs from 'minimist'
|
|
5
|
-
import isMain from 'es-main'
|
|
6
|
-
import helpMe from 'help-me'
|
|
7
|
-
import { readFile } from 'fs/promises'
|
|
8
|
-
import { join } from 'desm'
|
|
9
|
-
import { start, buildCompileCmd } from '@platformatic/service'
|
|
10
|
-
import { printAndExitLoadConfigError } from '@platformatic/config'
|
|
11
|
-
import { platformaticDB } from './index.js'
|
|
12
|
-
|
|
13
|
-
import { applyMigrations } from './lib/migrate.mjs'
|
|
14
|
-
import { seed } from './lib/seed.mjs'
|
|
15
|
-
import { generateTypes } from './lib/gen-types.mjs'
|
|
16
|
-
import { printGraphQLSchema, printOpenAPISchema, generateJsonSchemaConfig } from './lib/gen-schema.mjs'
|
|
17
|
-
import { generateMigration } from './lib/gen-migration.mjs'
|
|
18
|
-
import { createDB } from './lib/create.mjs'
|
|
19
|
-
|
|
20
|
-
const compile = buildCompileCmd(platformaticDB)
|
|
21
|
-
|
|
22
|
-
const help = helpMe({
|
|
23
|
-
dir: join(import.meta.url, 'help'),
|
|
24
|
-
// the default
|
|
25
|
-
ext: '.txt',
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
function wrapCommand (fn) {
|
|
29
|
-
return async function (...args) {
|
|
30
|
-
try {
|
|
31
|
-
return await fn(...args)
|
|
32
|
-
} catch (err) {
|
|
33
|
-
printAndExitLoadConfigError(err)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const program = commist({ maxDistance: 2 })
|
|
39
|
-
|
|
40
|
-
program.register('help', help.toStdout)
|
|
41
|
-
program.register('help start', help.toStdout.bind(null, ['start']))
|
|
42
|
-
program.register('help compile', help.toStdout.bind(null, ['compile']))
|
|
43
|
-
program.register('help migrations apply', help.toStdout.bind(null, ['migrations apply']))
|
|
44
|
-
program.register({ command: 'help seed', strict: true }, help.toStdout.bind(null, ['seed']))
|
|
45
|
-
program.register('help schema', help.toStdout.bind(null, ['schema']))
|
|
46
|
-
|
|
47
|
-
program.register('start', (argv) => {
|
|
48
|
-
start(platformaticDB, argv).catch(printAndExitLoadConfigError)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
program.register('create', wrapCommand(createDB))
|
|
52
|
-
program.register('compile', wrapCommand(compile))
|
|
53
|
-
program.register('migrations create', wrapCommand(generateMigration))
|
|
54
|
-
program.register('migrations apply', wrapCommand(applyMigrations))
|
|
55
|
-
program.register('seed', wrapCommand(seed))
|
|
56
|
-
program.register('types', wrapCommand(generateTypes))
|
|
57
|
-
program.register('schema graphql', wrapCommand(printGraphQLSchema))
|
|
58
|
-
program.register('schema openapi', wrapCommand(printOpenAPISchema))
|
|
59
|
-
program.register('schema config', wrapCommand(generateJsonSchemaConfig))
|
|
60
|
-
program.register('schema', help.toStdout.bind(null, ['schema']))
|
|
61
|
-
|
|
62
|
-
// TODO add help command
|
|
63
|
-
|
|
64
|
-
export async function runDB (argv) {
|
|
65
|
-
const args = parseArgs(argv, {
|
|
66
|
-
alias: {
|
|
67
|
-
v: 'version',
|
|
68
|
-
},
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
if (args.version) {
|
|
72
|
-
console.log('v' + JSON.parse(await readFile(join(import.meta.url, 'package.json'), 'utf-8')).version)
|
|
73
|
-
process.exit(0)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const output = await program.parseAsync(argv)
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
output,
|
|
80
|
-
help,
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (isMain(import.meta)) {
|
|
85
|
-
await runDB(process.argv.splice(2))
|
|
86
|
-
}
|
package/help/compile.txt
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Compile typescript plugins.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic db compile
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
As a result of executing this command, the Platformatic DB will compile typescript
|
|
8
|
-
plugins in the `outDir` directory.
|
|
9
|
-
|
|
10
|
-
If not specified, the configuration will be loaded from any of the following, in the current directory.
|
|
11
|
-
|
|
12
|
-
* `platformatic.json`, or
|
|
13
|
-
* `platformatic.yml`, or
|
|
14
|
-
* `platformatic.tml`
|
|
15
|
-
|
|
16
|
-
You can find more details about the configuration format here:
|
|
17
|
-
* [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
|
package/help/create.txt
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Creates a new Platformatic DB application.
|
|
2
|
-
|
|
3
|
-
Options are
|
|
4
|
-
|
|
5
|
-
* `dir <string>` - the directory where to create the project (Default: `process.cwd() + 'platformatic-composer'`)
|
|
6
|
-
* `port <string>` - the port where the application will listen (Default: `3042`)
|
|
7
|
-
* `hostname <string>` - the hostname where the application will listen (Default: `0.0.0.0`)
|
|
8
|
-
* `connectionString <string>` - the connection string for your database (Default: `sqlite://./db.sqlite`)
|
|
9
|
-
* `migrations <boolean>` - Creates sample migrations (Default: `true`)
|
|
10
|
-
* `git <boolean>` - Init the git repository (Default: `true`)
|
|
11
|
-
* `typescript <boolean>` - Use Typescript (Default: `false`)
|
|
12
|
-
* `install <boolean>` - Run or not `npm install` after creating the files (Default: `true`)
|
|
13
|
-
* `plugin <boolean>` - Creates a sample plugin and tests (Default: `true`)
|
package/help/help.txt
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Available commands:
|
|
2
|
-
|
|
3
|
-
* `help` - show this help message.
|
|
4
|
-
* `help <command>` - shows more information about a command.
|
|
5
|
-
* `start` - start the server.
|
|
6
|
-
* `compile` - compile typescript plugins.
|
|
7
|
-
* `seed` - run a seed file.
|
|
8
|
-
* `types` - generate typescript types for entities.
|
|
9
|
-
* `schema` - generate and print api schema.
|
|
10
|
-
* `migrations create` - generate do and undo migration files.
|
|
11
|
-
* `migrations apply` - apply migration files.
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
Apply all configured migrations to the database:
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic db migrations apply
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
The migrations will be applied in the order they are specified in the
|
|
8
|
-
folder defined in the configuration file. If you want to apply a specific migration,
|
|
9
|
-
you can use the `--to` option:
|
|
10
|
-
|
|
11
|
-
``` bash
|
|
12
|
-
$ platformatic db migrations apply --to 001
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Here is an example migration:
|
|
16
|
-
|
|
17
|
-
``` sql
|
|
18
|
-
CREATE TABLE graphs (
|
|
19
|
-
id SERIAL PRIMARY KEY,
|
|
20
|
-
name TEXT
|
|
21
|
-
);
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
You can always rollback to a specific migration with:
|
|
25
|
-
|
|
26
|
-
``` bash
|
|
27
|
-
$ platformatic db migrations apply --to VERSION
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Use 000 to reset to the initial state.
|
|
31
|
-
|
|
32
|
-
Options:
|
|
33
|
-
|
|
34
|
-
* `-c, --config <path>` - Path to the configuration file.
|
|
35
|
-
* `-t, --to <version>` - Migrate to a specific version.
|
|
36
|
-
|
|
37
|
-
If not specified, the configuration will be loaded from any of the following, in the current directory.
|
|
38
|
-
|
|
39
|
-
* `platformatic.json`, or
|
|
40
|
-
* `platformatic.yml`, or
|
|
41
|
-
* `platformatic.tml`
|
|
42
|
-
|
|
43
|
-
You can find more details about the configuration format here:
|
|
44
|
-
* [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
|
|
45
|
-
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Create next migration files.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic db migrations create
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
It will generate do and undo sql files in the migrations folder. The name of the
|
|
8
|
-
files will be the next migration number.
|
|
9
|
-
|
|
10
|
-
``` bash
|
|
11
|
-
$ platformatic db migrations create
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
The migration files are named `001.<do|undo>.sql`, `002.<do|undo>.sql` etc...
|
|
15
|
-
|
|
16
|
-
Options:
|
|
17
|
-
|
|
18
|
-
* `-c, --config <path>` - Path to the configuration file.
|
|
19
|
-
|
|
20
|
-
If not specified, the configuration will be loaded from any of the following, in the current directory.
|
|
21
|
-
|
|
22
|
-
* `platformatic.json`, or
|
|
23
|
-
* `platformatic.yml`, or
|
|
24
|
-
* `platformatic.tml`
|
|
25
|
-
|
|
26
|
-
You can find more details about the configuration format here:
|
|
27
|
-
* [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
|
package/help/migrations.txt
DELETED
package/help/schema.txt
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
Update the config schema file:
|
|
2
|
-
|
|
3
|
-
* `schema config` - update the JSON schema config available on `platformatic.json`
|
|
4
|
-
|
|
5
|
-
Your configuration on `platformatic.json` has a schema defined to improve the developer experience and avoid mistakes when updating the configuration of Platformatic DB.
|
|
6
|
-
When you run `platformatic db init`, a new JSON `$schema` property is added in `platformatic.json`. This can allow your IDE to add suggestions (f.e. mandatory/missing fields, types, default values) by opening the config in `platformatic.json`.
|
|
7
|
-
Running `platformatic schema config` you can update your schema so that it matches well the latest changes available on your config.
|
|
8
|
-
|
|
9
|
-
Generate a schema from the database and prints it to standard output:
|
|
10
|
-
|
|
11
|
-
* `schema graphql` - generate the GraphQL schema
|
|
12
|
-
* `schema openapi` - generate the OpenAPI schema
|
|
13
|
-
|
|
14
|
-
Options:
|
|
15
|
-
|
|
16
|
-
* `-c, --config FILE` - Specify a configuration file to use.
|
|
17
|
-
|
|
18
|
-
If not specified, the configuration will be loaded from any of the following, in the current directory.
|
|
19
|
-
|
|
20
|
-
* `platformatic.json`, or
|
|
21
|
-
* `platformatic.yml`, or
|
|
22
|
-
* `platformatic.tml`
|
|
23
|
-
|
|
24
|
-
You can find more details about the configuration format here:
|
|
25
|
-
* [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
|
package/help/seed.txt
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
Load a seed into the database. This is a convenience method that loads
|
|
2
|
-
a JavaScript file and configure @platformatic/sql-mapper to connect to
|
|
3
|
-
the database specified in the configuration file.
|
|
4
|
-
|
|
5
|
-
Here is an example of a seed file:
|
|
6
|
-
|
|
7
|
-
``` javascript
|
|
8
|
-
'use strict'
|
|
9
|
-
|
|
10
|
-
module.exports = async function ({ entities, db, sql }) {
|
|
11
|
-
await entities.graph.save({ input: { name: 'Hello' } })
|
|
12
|
-
await db.query(sql`
|
|
13
|
-
INSERT INTO graphs (name) VALUES ('Hello 2');
|
|
14
|
-
`)
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
You can run this using the `seed` command:
|
|
19
|
-
|
|
20
|
-
``` bash
|
|
21
|
-
$ platformatic db seed seed.js
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Options:
|
|
25
|
-
|
|
26
|
-
* `--config` - Path to the configuration file.
|
|
27
|
-
|
|
28
|
-
If not specified, the configuration will be loaded from any of the following, in the current directory.
|
|
29
|
-
|
|
30
|
-
* `platformatic.json`, or
|
|
31
|
-
* `platformatic.yml`, or
|
|
32
|
-
* `platformatic.tml`
|
|
33
|
-
|
|
34
|
-
You can find more details about the configuration format here:
|
|
35
|
-
* [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
|
|
36
|
-
|
package/help/start.txt
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
Start the Platformatic DB server with the following command:
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic db start
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
You will need a configuration file. Here is an example to get you started,
|
|
8
|
-
save the following as `platformatic.json`:
|
|
9
|
-
|
|
10
|
-
``` json
|
|
11
|
-
{
|
|
12
|
-
"server": {
|
|
13
|
-
"hostname": "127.0.0.1",
|
|
14
|
-
"port": 0,
|
|
15
|
-
"logger": {
|
|
16
|
-
"level": "info"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"db": {
|
|
20
|
-
"connectionString": "sqlite://./db"
|
|
21
|
-
},
|
|
22
|
-
"migrations": {
|
|
23
|
-
"dir": "./migrations"
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Remember to create a migration, run the `db help migrate` command to know more.
|
|
29
|
-
|
|
30
|
-
All outstanding migrations will be applied to the database unless the
|
|
31
|
-
`migrations.autoApply` configuration option is set to false.
|
|
32
|
-
|
|
33
|
-
By sending the SIGUSR2 signal, the server can be reloaded.
|
|
34
|
-
|
|
35
|
-
Options:
|
|
36
|
-
|
|
37
|
-
* `-c, --config FILE` - Specify a configuration file to use.
|
|
38
|
-
|
|
39
|
-
If not specified, the configuration will be loaded from any of the following, in the current directory.
|
|
40
|
-
|
|
41
|
-
* `platformatic.json`, or
|
|
42
|
-
* `platformatic.yml`, or
|
|
43
|
-
* `platformatic.tml`
|
|
44
|
-
|
|
45
|
-
You can find more details about the configuration format here:
|
|
46
|
-
* [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
|
|
47
|
-
|
package/help/types.txt
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
Generate typescript types for your entities from the database.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic db types
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
As a result of executing this command, the Platformatic DB will generate a `types`
|
|
8
|
-
folder with a typescript file for each database entity. It will also generate a
|
|
9
|
-
`global.d.ts` file that injects the types into the Application instance.
|
|
10
|
-
|
|
11
|
-
In order to add type support to your plugins, you need to install some additional
|
|
12
|
-
dependencies. To do this, copy and run an `npm install` command with dependencies
|
|
13
|
-
that "platformatic db types" will ask you.
|
|
14
|
-
|
|
15
|
-
Here is an example of a platformatic plugin.js with jsdoc support.
|
|
16
|
-
You can use it to add autocomplete to your code.
|
|
17
|
-
|
|
18
|
-
``` javascript
|
|
19
|
-
/// <reference path="./global.d.ts" />
|
|
20
|
-
'use strict'
|
|
21
|
-
|
|
22
|
-
/** @param {import('fastify').FastifyInstance} app */
|
|
23
|
-
module.exports = async function (app) {
|
|
24
|
-
app.get('/movie', async () => {
|
|
25
|
-
const movies = await app.platformatic.entities.movie.find({
|
|
26
|
-
where: { title: { eq: 'The Hitchhiker\'s Guide to the Galaxy' } }
|
|
27
|
-
})
|
|
28
|
-
return movies[0].id
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
If not specified, the configuration will be loaded from any of the following, in the current directory.
|
|
34
|
-
|
|
35
|
-
* `platformatic.json`, or
|
|
36
|
-
* `platformatic.yml`, or
|
|
37
|
-
* `platformatic.tml`
|
|
38
|
-
|
|
39
|
-
You can find more details about the configuration format here:
|
|
40
|
-
* [Platformatic DB Configuration](https://docs.platformatic.dev/docs/db/configuration)
|
package/index.test-d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { buildServer, PlatformaticApp, PlatformaticDBMixin, PlatformaticDBConfig, Entities, errors } from '.'
|
|
2
|
-
import ConfigManager from '@platformatic/config'
|
|
3
|
-
import type { Database } from '@platformatic/sql-mapper'
|
|
4
|
-
import { SQL } from '@databases/sql'
|
|
5
|
-
import { expectType } from 'tsd'
|
|
6
|
-
import { OpenAPI } from 'openapi-types'
|
|
7
|
-
import type { MercuriusPlugin } from 'mercurius'
|
|
8
|
-
import { FastifyError } from '@fastify/error'
|
|
9
|
-
|
|
10
|
-
declare module 'fastify' {
|
|
11
|
-
interface FastifyInstance {
|
|
12
|
-
platformatic: PlatformaticApp<PlatformaticDBConfig> & PlatformaticDBMixin<Entities>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function main (): Promise<void> {
|
|
17
|
-
// TODO this configuration is incomplete, type it fully
|
|
18
|
-
const server = await buildServer({
|
|
19
|
-
server: {
|
|
20
|
-
port: 3042,
|
|
21
|
-
host: '127.0.0.1',
|
|
22
|
-
},
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
expectType<Database>(server.platformatic.db)
|
|
26
|
-
expectType<SQL>(server.platformatic.sql)
|
|
27
|
-
expectType<ConfigManager<PlatformaticDBConfig>>(server.platformatic.configManager)
|
|
28
|
-
expectType<PlatformaticDBConfig>(server.platformatic.config)
|
|
29
|
-
expectType<OpenAPI.Document>(server.swagger())
|
|
30
|
-
expectType<MercuriusPlugin>(server.graphql)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
main().catch(console.error)
|
|
34
|
-
|
|
35
|
-
// Errors
|
|
36
|
-
type ErrorWithNoParams = () => FastifyError
|
|
37
|
-
type ErrorWithOneParam = (param: string) => FastifyError
|
|
38
|
-
|
|
39
|
-
expectType<ErrorWithNoParams>(errors.MigrateMissingMigrationsError)
|
|
40
|
-
expectType<ErrorWithNoParams>(errors.UnknownDatabaseError)
|
|
41
|
-
expectType<ErrorWithOneParam>(errors.MigrateMissingMigrationsDirError)
|
|
42
|
-
expectType<ErrorWithNoParams>(errors.MissingSeedFileError)
|
|
43
|
-
expectType<ErrorWithNoParams>(errors.MigrationsToApplyError)
|
package/lib/adjust-config.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const { resolve } = require('path')
|
|
3
|
-
const { readFile } = require('fs/promises')
|
|
4
|
-
const { platformaticService } = require('@platformatic/service')
|
|
5
|
-
|
|
6
|
-
module.exports = async function adjustConfig (configManager) {
|
|
7
|
-
await platformaticService.configManagerConfig.transformConfig.call(configManager)
|
|
8
|
-
|
|
9
|
-
const dirOfConfig = configManager.dirname
|
|
10
|
-
if (configManager.current.db && configManager.current.db.connectionString.indexOf('sqlite') === 0 && configManager.current.db.connectionString !== 'sqlite://:memory:') {
|
|
11
|
-
const originalSqlitePath = configManager.current.db.connectionString.replace('sqlite://', '')
|
|
12
|
-
const sqliteFullPath = resolve(dirOfConfig, originalSqlitePath)
|
|
13
|
-
configManager.current.db.connectionString = 'sqlite://' + sqliteFullPath
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/* c8 ignore next 3 */
|
|
17
|
-
if (configManager.current.db.graphql?.schemaPath) {
|
|
18
|
-
configManager.current.db.graphql.schema = await readFile(configManager.current.db.graphql.schemaPath, 'utf8')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/* c8 ignore next 2 */
|
|
22
|
-
const arePostgresqlSchemaDefined = configManager.current.db?.connectionString.indexOf('postgres') === 0 && configManager.current.db?.schema?.length > 0
|
|
23
|
-
const migrationsTableName = arePostgresqlSchemaDefined ? 'public.versions' : 'versions'
|
|
24
|
-
|
|
25
|
-
// relative-to-absolute migrations path
|
|
26
|
-
if (configManager.current.migrations) {
|
|
27
|
-
configManager.current.migrations.table = configManager.current.migrations.table || migrationsTableName
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (configManager.current.migrations && configManager.current.db) {
|
|
31
|
-
// TODO remove the ignores
|
|
32
|
-
/* c8 ignore next 4 */
|
|
33
|
-
configManager.current.db.ignore = configManager.current.db.ignore || {}
|
|
34
|
-
configManager.current.db.ignore = Object.assign({}, {
|
|
35
|
-
[configManager.current.migrations.table || migrationsTableName]: true,
|
|
36
|
-
}, configManager.current.db.ignore)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (configManager.current.types?.autogenerate === 'true') {
|
|
40
|
-
configManager.current.types.autogenerate = true
|
|
41
|
-
}
|
|
42
|
-
}
|
package/lib/create.mjs
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
import minimist from 'minimist'
|
|
3
|
-
import { Generator } from '../lib/generator/db-generator.js'
|
|
4
|
-
import { join } from 'node:path'
|
|
5
|
-
import { getPkgManager } from '@platformatic/utils'
|
|
6
|
-
import { execa } from 'execa'
|
|
7
|
-
import ora from 'ora'
|
|
8
|
-
import { Table } from 'console-table-printer'
|
|
9
|
-
import pino from 'pino'
|
|
10
|
-
import pinoPretty from 'pino-pretty'
|
|
11
|
-
|
|
12
|
-
function printAppSummary (args, logger) {
|
|
13
|
-
logger.info('Creating a Platformatic DB app with this config: ')
|
|
14
|
-
const table = [
|
|
15
|
-
{ config: 'Directory', value: args.dir },
|
|
16
|
-
{ config: 'Connection String', value: args.connectionString },
|
|
17
|
-
{ config: 'Language', value: args.typescript ? 'Typescript' : 'Javascript' },
|
|
18
|
-
{ config: 'Init Git Repository', value: args.git },
|
|
19
|
-
{ config: 'Install Dependencies', value: args.install },
|
|
20
|
-
{ config: 'Sample Plugin and Tests', value: args.plugin },
|
|
21
|
-
{ config: 'Create Sample Migrations', value: args.migrations },
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
const p = new Table({
|
|
25
|
-
columns: [
|
|
26
|
-
{ name: 'config', alignment: 'right' },
|
|
27
|
-
{ name: 'value', alignment: 'left' },
|
|
28
|
-
],
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
p.addRows(table)
|
|
32
|
-
p.printTable()
|
|
33
|
-
}
|
|
34
|
-
async function createDB (_args) {
|
|
35
|
-
const stream = pinoPretty({
|
|
36
|
-
translateTime: 'SYS:HH:MM:ss',
|
|
37
|
-
ignore: 'hostname,pid',
|
|
38
|
-
minimumLevel: 'debug',
|
|
39
|
-
sync: true,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const logger = pino(stream)
|
|
43
|
-
|
|
44
|
-
const args = minimist(process.argv.slice(2), {
|
|
45
|
-
string: ['dir', 'port', 'hostname', 'connectionString'],
|
|
46
|
-
boolean: ['typescript', 'install', 'migrations', 'plugin', 'git'],
|
|
47
|
-
default: {
|
|
48
|
-
dir: join(process.cwd(), 'platformatic-db'),
|
|
49
|
-
port: 3042,
|
|
50
|
-
hostname: '0.0.0.0',
|
|
51
|
-
plugin: true,
|
|
52
|
-
typescript: false,
|
|
53
|
-
git: false,
|
|
54
|
-
install: true,
|
|
55
|
-
migrations: true,
|
|
56
|
-
connectionString: 'sqlite://./db.sqlite',
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
printAppSummary(args, logger)
|
|
62
|
-
|
|
63
|
-
const gen = new Generator({})
|
|
64
|
-
gen.setConfig({
|
|
65
|
-
port: args.port,
|
|
66
|
-
hostname: args.hostname,
|
|
67
|
-
plugin: args.plugin,
|
|
68
|
-
tests: args.plugin,
|
|
69
|
-
typescript: args.typescript,
|
|
70
|
-
initGitRepository: args.git,
|
|
71
|
-
targetDirectory: args.dir,
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
await gen.run()
|
|
76
|
-
if (args.install) {
|
|
77
|
-
const pkgManager = getPkgManager()
|
|
78
|
-
const spinner = ora('Installing dependencies...').start()
|
|
79
|
-
await execa(pkgManager, ['install'], { cwd: args.dir })
|
|
80
|
-
spinner.succeed()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
logger.info('Done! 🎉')
|
|
84
|
-
} catch (err) {
|
|
85
|
-
logger.error(err.message)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export { createDB }
|
package/lib/gen-migration.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
2
|
-
import { writeFile } from 'fs/promises'
|
|
3
|
-
import pino from 'pino'
|
|
4
|
-
import pretty from 'pino-pretty'
|
|
5
|
-
import { loadConfig } from '@platformatic/config'
|
|
6
|
-
import { Migrator } from './migrator.mjs'
|
|
7
|
-
import { platformaticDB } from '../index.js'
|
|
8
|
-
import errors from './errors.js'
|
|
9
|
-
|
|
10
|
-
async function generateMigration (_args) {
|
|
11
|
-
const logger = pino(pretty({
|
|
12
|
-
translateTime: 'SYS:HH:MM:ss',
|
|
13
|
-
ignore: 'hostname,pid',
|
|
14
|
-
}))
|
|
15
|
-
|
|
16
|
-
const { configManager } = await loadConfig({}, _args, platformaticDB)
|
|
17
|
-
await configManager.parseAndValidate()
|
|
18
|
-
const config = configManager.current
|
|
19
|
-
|
|
20
|
-
let migrator = null
|
|
21
|
-
try {
|
|
22
|
-
const migrationsConfig = config.migrations
|
|
23
|
-
if (migrationsConfig === undefined) {
|
|
24
|
-
throw new errors.MigrateMissingMigrationsError()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
migrator = new Migrator(migrationsConfig, config.db, logger)
|
|
28
|
-
|
|
29
|
-
const nextMigrationVersion = await migrator.getNextMigrationVersion()
|
|
30
|
-
const nextMigrationVersionStr = migrator.convertVersionToStr(nextMigrationVersion)
|
|
31
|
-
|
|
32
|
-
const nextDoMigrationName = `${nextMigrationVersionStr}.do.sql`
|
|
33
|
-
const nextUndoMigrationName = `${nextMigrationVersionStr}.undo.sql`
|
|
34
|
-
|
|
35
|
-
const doFile = join(migrator.migrationDir, nextDoMigrationName)
|
|
36
|
-
const undoFile = join(migrator.migrationDir, nextUndoMigrationName)
|
|
37
|
-
|
|
38
|
-
await Promise.all([
|
|
39
|
-
writeFile(doFile, ''),
|
|
40
|
-
writeFile(undoFile, ''),
|
|
41
|
-
])
|
|
42
|
-
|
|
43
|
-
logger.info({ do: doFile, undo: undoFile }, 'Created migration files')
|
|
44
|
-
} catch (error) {
|
|
45
|
-
logger.error(error.message)
|
|
46
|
-
} finally {
|
|
47
|
-
if (migrator !== null) {
|
|
48
|
-
await migrator.close()
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export { generateMigration }
|