@platformatic/db 3.4.1 → 3.5.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/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/schema.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
'use strict'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { schemaComponents as basicSchemaComponents } from '@platformatic/basic'
|
|
4
|
+
import {
|
|
5
|
+
fastifyServer as server,
|
|
6
|
+
schemaComponents as utilsSchemaComponents,
|
|
7
|
+
watch,
|
|
8
|
+
wrappedRuntime
|
|
9
|
+
} from '@platformatic/foundation'
|
|
10
|
+
import { schemaComponents as serviceSchemaComponents } from '@platformatic/service'
|
|
11
|
+
import { readFileSync } from 'node:fs'
|
|
12
|
+
import { resolve } from 'node:path'
|
|
7
13
|
|
|
8
|
-
const
|
|
14
|
+
export const packageJson = JSON.parse(readFileSync(resolve(import.meta.dirname, '../package.json'), 'utf8'))
|
|
15
|
+
export const version = packageJson.version
|
|
16
|
+
|
|
17
|
+
const { plugins, openApiBase, $defs } = serviceSchemaComponents
|
|
18
|
+
|
|
19
|
+
export const db = {
|
|
9
20
|
type: 'object',
|
|
10
21
|
properties: {
|
|
11
22
|
connectionString: {
|
|
@@ -234,7 +245,7 @@ const db = {
|
|
|
234
245
|
required: ['connectionString']
|
|
235
246
|
}
|
|
236
247
|
|
|
237
|
-
const sharedAuthorizationRule = {
|
|
248
|
+
export const sharedAuthorizationRule = {
|
|
238
249
|
role: {
|
|
239
250
|
type: 'string',
|
|
240
251
|
description: 'the role name to match the rule'
|
|
@@ -254,10 +265,13 @@ const sharedAuthorizationRule = {
|
|
|
254
265
|
},
|
|
255
266
|
delete: {
|
|
256
267
|
$ref: '#/$defs/crud-operation-auth'
|
|
268
|
+
},
|
|
269
|
+
updateMany: {
|
|
270
|
+
$ref: '#/$defs/crud-operation-auth'
|
|
257
271
|
}
|
|
258
272
|
}
|
|
259
273
|
|
|
260
|
-
const authorization = {
|
|
274
|
+
export const authorization = {
|
|
261
275
|
type: 'object',
|
|
262
276
|
properties: {
|
|
263
277
|
adminSecret: {
|
|
@@ -363,7 +377,7 @@ const authorization = {
|
|
|
363
377
|
additionalProperties: false
|
|
364
378
|
}
|
|
365
379
|
|
|
366
|
-
const migrations = {
|
|
380
|
+
export const migrations = {
|
|
367
381
|
type: 'object',
|
|
368
382
|
properties: {
|
|
369
383
|
dir: {
|
|
@@ -406,7 +420,7 @@ const migrations = {
|
|
|
406
420
|
required: ['dir']
|
|
407
421
|
}
|
|
408
422
|
|
|
409
|
-
const types = {
|
|
423
|
+
export const types = {
|
|
410
424
|
type: 'object',
|
|
411
425
|
properties: {
|
|
412
426
|
autogenerate: {
|
|
@@ -429,10 +443,18 @@ const types = {
|
|
|
429
443
|
additionalProperties: false
|
|
430
444
|
}
|
|
431
445
|
|
|
432
|
-
const
|
|
433
|
-
|
|
446
|
+
export const schemaComponents = {
|
|
447
|
+
db,
|
|
448
|
+
sharedAuthorizationRule,
|
|
449
|
+
authorization,
|
|
450
|
+
migrations,
|
|
451
|
+
types
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export const schema = {
|
|
455
|
+
$id: `https://schemas.platformatic.dev/@platformatic/db/${packageJson.version}.json`,
|
|
434
456
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
435
|
-
title: 'Platformatic
|
|
457
|
+
title: 'Platformatic Database Config',
|
|
436
458
|
type: 'object',
|
|
437
459
|
properties: {
|
|
438
460
|
basePath: {
|
|
@@ -451,11 +473,11 @@ const platformaticDBschema = {
|
|
|
451
473
|
db,
|
|
452
474
|
authorization,
|
|
453
475
|
migrations,
|
|
454
|
-
metrics,
|
|
455
476
|
types,
|
|
456
477
|
plugins,
|
|
457
|
-
|
|
458
|
-
|
|
478
|
+
application: basicSchemaComponents.application,
|
|
479
|
+
telemetry: utilsSchemaComponents.telemetry,
|
|
480
|
+
runtime: wrappedRuntime,
|
|
459
481
|
watch: {
|
|
460
482
|
anyOf: [
|
|
461
483
|
watch,
|
|
@@ -477,7 +499,7 @@ const platformaticDBschema = {
|
|
|
477
499
|
additionalProperties: false,
|
|
478
500
|
required: ['db'],
|
|
479
501
|
$defs: {
|
|
480
|
-
|
|
502
|
+
...$defs,
|
|
481
503
|
'crud-operation-auth': {
|
|
482
504
|
oneOf: [
|
|
483
505
|
{
|
|
@@ -529,8 +551,7 @@ const platformaticDBschema = {
|
|
|
529
551
|
}
|
|
530
552
|
}
|
|
531
553
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
console.log(JSON.stringify(platformaticDBschema, null, 2))
|
|
554
|
+
/* c8 ignore next 3 */
|
|
555
|
+
if (process.argv[1] === import.meta.filename) {
|
|
556
|
+
console.log(JSON.stringify(schema, null, 2))
|
|
536
557
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const jsHelperSqlite = {
|
|
1
|
+
export const jsHelperSqlite = {
|
|
4
2
|
requires: `
|
|
5
3
|
const os = require('node:os')
|
|
6
4
|
const path = require('node:path')
|
|
@@ -21,10 +19,10 @@ let counter = 0
|
|
|
21
19
|
t.after(async () => {
|
|
22
20
|
await fs.unlink(dbPath)
|
|
23
21
|
})
|
|
24
|
-
|
|
22
|
+
`
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
function jsHelperPostgres (connectionString) {
|
|
25
|
+
export function jsHelperPostgres (connectionString) {
|
|
28
26
|
return {
|
|
29
27
|
// TODO(mcollina): replace sql-mapper
|
|
30
28
|
requires: `
|
|
@@ -62,11 +60,11 @@ let counter = 0
|
|
|
62
60
|
\`)
|
|
63
61
|
await db.dispose()
|
|
64
62
|
})
|
|
65
|
-
|
|
63
|
+
`
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
function jsHelperMySQL (connectionString) {
|
|
67
|
+
export function jsHelperMySQL (connectionString) {
|
|
70
68
|
return {
|
|
71
69
|
// TODO(mcollina): replace sql-mapper
|
|
72
70
|
requires: `
|
|
@@ -104,11 +102,11 @@ let counter = 0
|
|
|
104
102
|
\`)
|
|
105
103
|
await db.dispose()
|
|
106
104
|
})
|
|
107
|
-
|
|
105
|
+
`
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
108
|
|
|
111
|
-
const moviesTestJS = `\
|
|
109
|
+
export const moviesTestJS = `\
|
|
112
110
|
'use strict'
|
|
113
111
|
|
|
114
112
|
const test = require('node:test')
|
|
@@ -160,7 +158,7 @@ test('movies', async (t) => {
|
|
|
160
158
|
})
|
|
161
159
|
`
|
|
162
160
|
|
|
163
|
-
const moviesTestTS = `\
|
|
161
|
+
export const moviesTestTS = `\
|
|
164
162
|
import test from 'node:test'
|
|
165
163
|
import assert from 'node:assert'
|
|
166
164
|
import { getServer } from '../helper'
|
|
@@ -210,10 +208,53 @@ test('movies', async (t) => {
|
|
|
210
208
|
})
|
|
211
209
|
`
|
|
212
210
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
211
|
+
export const README = `
|
|
212
|
+
# Platformatic DB API
|
|
213
|
+
|
|
214
|
+
This is a generated [Platformatic DB](https://docs.platformatic.dev/docs/db/overview) application.
|
|
215
|
+
|
|
216
|
+
## Requirements
|
|
217
|
+
|
|
218
|
+
Platformatic supports macOS, Linux and Windows ([WSL](https://docs.microsoft.com/windows/wsl/) recommended).
|
|
219
|
+
You'll need to have [Node.js](https://nodejs.org/) >= v18.8.0 or >= v20.6.0
|
|
220
|
+
|
|
221
|
+
## Setup
|
|
222
|
+
|
|
223
|
+
1. Install dependencies:
|
|
224
|
+
|
|
225
|
+
\`\`\`bash
|
|
226
|
+
npm install
|
|
227
|
+
\`\`\`
|
|
228
|
+
|
|
229
|
+
2. Apply migrations:
|
|
230
|
+
|
|
231
|
+
\`\`\`bash
|
|
232
|
+
npm run migrate
|
|
233
|
+
\`\`\`
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
## Usage
|
|
237
|
+
|
|
238
|
+
Run the API with:
|
|
239
|
+
|
|
240
|
+
\`\`\`bash
|
|
241
|
+
npm start
|
|
242
|
+
\`\`\`
|
|
243
|
+
|
|
244
|
+
### Explore
|
|
245
|
+
- ⚡ The Platformatic DB server is running at http://localhost:3042/
|
|
246
|
+
- 📔 View the REST API's Swagger documentation at http://localhost:3042/documentation/
|
|
247
|
+
- 🔍 Try out the GraphiQL web UI at http://localhost:3042/graphiql
|
|
248
|
+
|
|
249
|
+
`
|
|
250
|
+
|
|
251
|
+
export const ENVIRONMENT_TEMPLATE = `
|
|
252
|
+
import { type FastifyInstance } from 'fastify'
|
|
253
|
+
import { PlatformaticApplication, PlatformaticDatabaseConfig, PlatformaticDatabaseMixin, Entities } from '@platformatic/db'
|
|
254
|
+
|
|
255
|
+
declare module 'fastify' {
|
|
256
|
+
interface FastifyInstance {
|
|
257
|
+
platformatic: PlatformaticApplication<PlatformaticDatabaseConfig> & PlatformaticDatabaseMixin<Entities>
|
|
258
|
+
}
|
|
219
259
|
}
|
|
260
|
+
`
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { createDirectory, isFileAccessible, kMetadata } from '@platformatic/foundation'
|
|
2
|
+
import { mapOpenAPItoTypes, mapSQLEntityToJSONSchema } from '@platformatic/sql-json-schema-mapper'
|
|
3
|
+
import camelcase from 'camelcase'
|
|
4
|
+
import { readFile, readdir, unlink, writeFile } from 'node:fs/promises'
|
|
5
|
+
import { basename, join, relative, resolve, sep } from 'node:path'
|
|
6
|
+
import { setupDB } from './utils.js'
|
|
7
|
+
|
|
8
|
+
async function removeUnusedTypeFiles (entities, dir) {
|
|
9
|
+
const entityTypes = await readdir(dir)
|
|
10
|
+
const entityNames = Object.keys(entities)
|
|
11
|
+
const removedEntityNames = entityTypes.filter(
|
|
12
|
+
file => file !== 'index.d.ts' && !entityNames.includes(basename(file, '.d.ts'))
|
|
13
|
+
)
|
|
14
|
+
await Promise.all(removedEntityNames.map(file => unlink(join(dir, file))))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function generateEntityType (entity) {
|
|
18
|
+
const jsonSchema = mapSQLEntityToJSONSchema(entity)
|
|
19
|
+
const fieldDefinitions = Object.fromEntries(
|
|
20
|
+
Object.entries(entity.fields).map(([, value]) => [value.camelcase, value])
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const tsCode = mapOpenAPItoTypes(jsonSchema, fieldDefinitions, { indentSpaces: 2 })
|
|
24
|
+
|
|
25
|
+
entity.name = camelcase(entity.name).replace(/^\w/, c => c.toUpperCase())
|
|
26
|
+
return tsCode.replaceAll(/^declare interface/gm, 'export interface')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function generateIndexTypes (entities) {
|
|
30
|
+
const allImports = []
|
|
31
|
+
const allExports = []
|
|
32
|
+
const entityMembers = []
|
|
33
|
+
const entityTypesMembers = []
|
|
34
|
+
const entitiesHooks = []
|
|
35
|
+
const schemaGetters = []
|
|
36
|
+
|
|
37
|
+
const values = Object.entries(entities)
|
|
38
|
+
.map(([file, entity]) => [file, entity.name])
|
|
39
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
40
|
+
|
|
41
|
+
for (const [name, type] of values) {
|
|
42
|
+
allImports.push(`import { ${type} } from './${name}'`)
|
|
43
|
+
allExports.push(`export { ${type} } from './${name}'`)
|
|
44
|
+
entityMembers.push(` ${name}: Entity<${type}>`)
|
|
45
|
+
entityTypesMembers.push(` ${name}: ${type}`)
|
|
46
|
+
entitiesHooks.push(` addEntityHooks(entityName: '${name}', hooks: EntityHooks<${type}>): any`)
|
|
47
|
+
schemaGetters.push(`getSchema(schemaId: '${name}'): {
|
|
48
|
+
'$id': string,
|
|
49
|
+
title: string,
|
|
50
|
+
description: string,
|
|
51
|
+
type: string,
|
|
52
|
+
properties: { [x in keyof ${type}]: { type: string, nullable?: boolean } },
|
|
53
|
+
required: string[]
|
|
54
|
+
}`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const content = `import { Entity, EntityHooks, Entities as DatabaseEntities, PlatformaticDatabaseConfig, PlatformaticDatabaseMixin } from '@platformatic/db'
|
|
58
|
+
import { PlatformaticApplication, PlatformaticServiceConfig } from '@platformatic/service'
|
|
59
|
+
import { type FastifyInstance } from 'fastify'
|
|
60
|
+
|
|
61
|
+
${allImports.join('\n')}
|
|
62
|
+
|
|
63
|
+
${allExports.join('\n')}
|
|
64
|
+
|
|
65
|
+
export interface Entities extends DatabaseEntities {
|
|
66
|
+
${entityMembers.join('\n')}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface EntityTypes {
|
|
70
|
+
${entityTypesMembers.join('\n')}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface EntitiesHooks {
|
|
74
|
+
${entitiesHooks.join('\n')}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface SchemaGetters {
|
|
78
|
+
${schemaGetters.join('\n\n')}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type ServerInstance<Configuration = PlatformaticDatabaseConfig> = FastifyInstance & {
|
|
82
|
+
platformatic: PlatformaticApplication<Configuration> & PlatformaticDatabaseMixin<Entities> & EntitiesHooks & SchemaGetters
|
|
83
|
+
}
|
|
84
|
+
`
|
|
85
|
+
|
|
86
|
+
return content
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function generateEnvironmentTypes (folder) {
|
|
90
|
+
return `import { PlatformaticApplication, PlatformaticDatabaseConfig, PlatformaticDatabaseMixin } from "@platformatic/db";
|
|
91
|
+
import { Entities, EntitiesHooks, SchemaGetters } from "./${folder.replaceAll(sep, '/')}/index.js";
|
|
92
|
+
|
|
93
|
+
declare module "fastify" {
|
|
94
|
+
interface FastifyInstance {
|
|
95
|
+
platformatic: PlatformaticApplication<PlatformaticDatabaseConfig> & PlatformaticDatabaseMixin<Entities> & EntitiesHooks & SchemaGetters;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function writeFileIfChanged (filename, content) {
|
|
102
|
+
const isFileExists = await isFileAccessible(filename)
|
|
103
|
+
|
|
104
|
+
if (isFileExists) {
|
|
105
|
+
const fileContent = await readFile(filename, 'utf-8')
|
|
106
|
+
if (fileContent === content) {
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
await writeFile(filename, content)
|
|
112
|
+
return true
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function execute ({ logger, config }) {
|
|
116
|
+
const wrap = await setupDB(logger, config.db)
|
|
117
|
+
const { db, entities } = wrap
|
|
118
|
+
|
|
119
|
+
const count = Object.keys(entities).length
|
|
120
|
+
if (count === 0) {
|
|
121
|
+
// do not generate types if no schema is found
|
|
122
|
+
return 0
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const root = config[kMetadata].root
|
|
126
|
+
const typesFolderPath = resolve(root, config.types?.dir ?? 'types')
|
|
127
|
+
|
|
128
|
+
// Prepare the types folder
|
|
129
|
+
if (await isFileAccessible(typesFolderPath)) {
|
|
130
|
+
await removeUnusedTypeFiles(entities, typesFolderPath)
|
|
131
|
+
} else {
|
|
132
|
+
await createDirectory(typesFolderPath)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Generate all entities
|
|
136
|
+
for (const [name, entity] of Object.entries(entities)) {
|
|
137
|
+
const types = await generateEntityType(entity)
|
|
138
|
+
const pathToFile = join(typesFolderPath, name + '.d.ts')
|
|
139
|
+
|
|
140
|
+
if (await writeFileIfChanged(pathToFile, types)) {
|
|
141
|
+
logger.info(`Generated type for ${entity.name} entity.`)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Generate index.d.ts
|
|
146
|
+
const indexFilePath = join(typesFolderPath, 'index.d.ts')
|
|
147
|
+
const indexTypes = await generateIndexTypes(entities)
|
|
148
|
+
if (await writeFileIfChanged(indexFilePath, indexTypes)) {
|
|
149
|
+
logger.info('Regenerated index.d.ts.')
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Generate plt-env.d.ts
|
|
153
|
+
const environmentPath = join(root, 'plt-env.d.ts')
|
|
154
|
+
const pltEnvironment = await generateEnvironmentTypes(relative(root, typesFolderPath))
|
|
155
|
+
if (await writeFileIfChanged(environmentPath, pltEnvironment)) {
|
|
156
|
+
logger.info('Regenerated plt-env.d.ts.')
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
await db.dispose()
|
|
160
|
+
return count
|
|
161
|
+
}
|
package/lib/upgrade.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { abstractLogger } from '@platformatic/foundation'
|
|
2
|
+
import zeroSixteen from '@platformatic/service/lib/versions/0.16.0.js'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { loadMigrationsFromPath, semgrator } from 'semgrator'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
const
|
|
6
|
+
export async function upgrade (logger, config, version) {
|
|
7
|
+
const iterator = loadMigrationsFromPath(join(import.meta.dirname, 'versions'))
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
const { semgrator, loadMigrationsFromPath } = await import('semgrator')
|
|
8
|
-
|
|
9
|
-
const iterator = loadMigrationsFromPath(join(__dirname, 'versions'))
|
|
10
|
-
|
|
11
|
-
const migrations = [
|
|
12
|
-
zeroSixteen,
|
|
13
|
-
]
|
|
9
|
+
const migrations = [zeroSixteen]
|
|
14
10
|
|
|
15
11
|
for await (const migration of iterator) {
|
|
16
12
|
migrations.push(migration)
|
|
@@ -20,7 +16,7 @@ module.exports = async function upgrade (config, version) {
|
|
|
20
16
|
version,
|
|
21
17
|
migrations,
|
|
22
18
|
input: config,
|
|
23
|
-
logger:
|
|
19
|
+
logger: logger?.child({ name: '@platformatic/db' }) ?? abstractLogger
|
|
24
20
|
})
|
|
25
21
|
|
|
26
22
|
let result
|
package/lib/utils.js
CHANGED
|
@@ -1,45 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
import { connect } from '@platformatic/db-core'
|
|
2
|
+
import { kMetadata } from '@platformatic/foundation'
|
|
3
|
+
import fs from 'node:fs/promises'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
const { join, dirname } = require('path')
|
|
5
|
-
const { fileURLToPath } = require('url')
|
|
6
|
-
const fs = require('fs/promises')
|
|
7
|
-
const { isFileAccessible } = require('@platformatic/utils')
|
|
8
|
-
|
|
9
|
-
async function setupDB (log, config) {
|
|
7
|
+
export async function setupDB (log, config) {
|
|
10
8
|
const { db, sql, entities, dbschema } = await connect({ ...config, log })
|
|
11
9
|
|
|
12
10
|
return {
|
|
13
11
|
db,
|
|
14
12
|
sql,
|
|
15
13
|
entities,
|
|
16
|
-
dbschema
|
|
14
|
+
dbschema
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
function urlDirname (url) {
|
|
18
|
+
export function urlDirname (url) {
|
|
21
19
|
return dirname(fileURLToPath(url))
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
function locateSchemaLock (
|
|
25
|
-
return
|
|
22
|
+
export function locateSchemaLock (config) {
|
|
23
|
+
return config.db.schemalock.path ?? join(config[kMetadata].root, 'schema.lock')
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
async function updateSchemaLock (logger,
|
|
29
|
-
const config = configManager.current
|
|
26
|
+
export async function updateSchemaLock (logger, config) {
|
|
30
27
|
if (config.db.schemalock) {
|
|
31
28
|
const conn = await setupDB(logger, { ...config.db, dbschema: null })
|
|
32
|
-
const schemaLockPath = locateSchemaLock(
|
|
29
|
+
const schemaLockPath = locateSchemaLock(config)
|
|
33
30
|
await fs.writeFile(schemaLockPath, JSON.stringify(conn.dbschema, null, 2))
|
|
34
31
|
|
|
35
32
|
await conn.db.dispose()
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
|
|
39
|
-
module.exports = {
|
|
40
|
-
setupDB,
|
|
41
|
-
isFileAccessible,
|
|
42
|
-
urlDirname,
|
|
43
|
-
updateSchemaLock,
|
|
44
|
-
locateSchemaLock,
|
|
45
|
-
}
|
package/lib/versions/0.18.0.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports.migration = {
|
|
1
|
+
export default {
|
|
4
2
|
version: '0.28.0',
|
|
5
|
-
up
|
|
3
|
+
up (config) {
|
|
6
4
|
if (config.watch !== false) {
|
|
7
5
|
config.watch = typeof config.watch === 'object' ? config.watch : {}
|
|
8
6
|
|
|
@@ -15,5 +13,5 @@ module.exports.migration = {
|
|
|
15
13
|
delete config.db?.dashboard
|
|
16
14
|
|
|
17
15
|
return config
|
|
18
|
-
}
|
|
16
|
+
}
|
|
19
17
|
}
|
package/lib/versions/2.0.0.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { version } from '../schema.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
3
|
+
export default {
|
|
6
4
|
version: '2.0.0',
|
|
7
5
|
up: function (config) {
|
|
8
|
-
config.$schema = `https://schemas.platformatic.dev/@platformatic/db/${
|
|
6
|
+
config.$schema = `https://schemas.platformatic.dev/@platformatic/db/${version}.json`
|
|
9
7
|
return config
|
|
10
8
|
}
|
|
11
9
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
version: '2.99.0',
|
|
3
|
+
up (config) {
|
|
4
|
+
if (typeof config.plugins?.typescript !== 'undefined') {
|
|
5
|
+
delete config.plugins.typescript
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (typeof config.clients !== 'undefined') {
|
|
9
|
+
delete config.clients
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return config
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/db",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
"author": "Matteo Collina <hello@matteocollina.com>",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
|
|
11
9
|
"repository": {
|
|
12
10
|
"type": "git",
|
|
13
11
|
"url": "git+https://github.com/platformatic/platformatic.git"
|
|
@@ -20,22 +18,21 @@
|
|
|
20
18
|
"devDependencies": {
|
|
21
19
|
"@databases/pg": "^5.5.0",
|
|
22
20
|
"@databases/sql": "^3.3.0",
|
|
23
|
-
"@opentelemetry/api": "^1.
|
|
21
|
+
"@opentelemetry/api": "^1.9.0",
|
|
24
22
|
"ajv": "^8.12.0",
|
|
25
23
|
"bindings": "^1.5.0",
|
|
26
|
-
"borp": "^0.17.0",
|
|
27
24
|
"c8": "^10.0.0",
|
|
25
|
+
"cleaner-spec-reporter": "^0.5.0",
|
|
28
26
|
"eslint": "9",
|
|
29
|
-
"execa": "^
|
|
27
|
+
"execa": "^9.0.0",
|
|
30
28
|
"json-schema-to-typescript": "^15.0.0",
|
|
31
|
-
"mercurius": "^
|
|
32
|
-
"neostandard": "^0.
|
|
29
|
+
"mercurius": "^16.0.0",
|
|
30
|
+
"neostandard": "^0.12.0",
|
|
33
31
|
"openapi-types": "^12.1.3",
|
|
34
32
|
"split2": "^4.2.0",
|
|
35
|
-
"
|
|
36
|
-
"tsd": "^0.31.0",
|
|
33
|
+
"tsd": "^0.33.0",
|
|
37
34
|
"typescript": "^5.5.4",
|
|
38
|
-
"undici": "^
|
|
35
|
+
"undici": "^7.0.0",
|
|
39
36
|
"vscode-json-languageservice": "^5.3.9",
|
|
40
37
|
"why-is-node-running": "^2.2.2",
|
|
41
38
|
"yaml": "^2.4.1"
|
|
@@ -51,49 +48,44 @@
|
|
|
51
48
|
"camelcase": "^6.3.0",
|
|
52
49
|
"close-with-grace": "^2.0.0",
|
|
53
50
|
"code-block-writer": "^13.0.1",
|
|
54
|
-
"commist": "^3.2.0",
|
|
55
51
|
"console-table-printer": "^2.12.0",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"es-main": "^1.3.0",
|
|
59
|
-
"execa": "^8.0.1",
|
|
52
|
+
"env-schema": "^6.0.0",
|
|
53
|
+
"execa": "^9.0.0",
|
|
60
54
|
"fastify": "^5.0.0",
|
|
61
55
|
"fastify-metrics": "^12.0.0",
|
|
62
56
|
"fastify-plugin": "^5.0.0",
|
|
63
|
-
"fastify-print-routes": "^
|
|
57
|
+
"fastify-print-routes": "^4.0.0",
|
|
64
58
|
"graphql": "^16.8.1",
|
|
65
59
|
"help-me": "^5.0.0",
|
|
66
60
|
"minimist": "^1.2.8",
|
|
67
61
|
"my-ua-parser": "^2.0.2",
|
|
68
62
|
"ora": "^6.3.1",
|
|
69
|
-
"pino": "^
|
|
70
|
-
"pino-pretty": "^
|
|
71
|
-
"postgrator": "^
|
|
63
|
+
"pino": "^9.9.0",
|
|
64
|
+
"pino-pretty": "^13.0.0",
|
|
65
|
+
"postgrator": "^8.0.0",
|
|
72
66
|
"rfdc": "^1.3.1",
|
|
73
67
|
"rimraf": "^4.4.1",
|
|
74
68
|
"semgrator": "^0.3.0",
|
|
75
|
-
"@platformatic/
|
|
76
|
-
"@platformatic/db-authorization": "3.
|
|
77
|
-
"@platformatic/
|
|
78
|
-
"@platformatic/
|
|
79
|
-
"@platformatic/service": "3.
|
|
80
|
-
"@platformatic/sql-
|
|
81
|
-
"@platformatic/sql-json-schema-mapper": "3.
|
|
82
|
-
"@platformatic/sql-mapper": "3.
|
|
83
|
-
"@platformatic/
|
|
84
|
-
"@platformatic/
|
|
85
|
-
"@platformatic/
|
|
86
|
-
|
|
87
|
-
|
|
69
|
+
"@platformatic/basic": "3.5.1",
|
|
70
|
+
"@platformatic/db-authorization": "3.5.1",
|
|
71
|
+
"@platformatic/db-core": "3.5.1",
|
|
72
|
+
"@platformatic/foundation": "3.5.1",
|
|
73
|
+
"@platformatic/service": "3.5.1",
|
|
74
|
+
"@platformatic/sql-events": "3.5.1",
|
|
75
|
+
"@platformatic/sql-json-schema-mapper": "3.5.1",
|
|
76
|
+
"@platformatic/sql-mapper": "3.5.1",
|
|
77
|
+
"@platformatic/sql-graphql": "3.5.1",
|
|
78
|
+
"@platformatic/sql-openapi": "3.5.1",
|
|
79
|
+
"@platformatic/telemetry": "3.5.1"
|
|
80
|
+
},
|
|
81
|
+
"engines": {
|
|
82
|
+
"node": ">=22.19.0"
|
|
88
83
|
},
|
|
89
84
|
"scripts": {
|
|
90
|
-
"test": "
|
|
91
|
-
"test:postgresql": "DB=postgresql borp -T --concurrency=1 --timeout=180000",
|
|
92
|
-
"test:mariadb": "DB=mariadb borp -T --concurrency=1 --timeout=180000",
|
|
93
|
-
"test:mysql": "DB=mysql borp -T --concurrency=1 --timeout=180000",
|
|
85
|
+
"test": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",
|
|
94
86
|
"gen-schema": "node lib/schema.js > schema.json",
|
|
95
87
|
"gen-types": "json2ts > config.d.ts < schema.json",
|
|
96
|
-
"build": "
|
|
88
|
+
"build": "npm run gen-schema && npm run gen-types",
|
|
97
89
|
"lint": "eslint"
|
|
98
90
|
}
|
|
99
91
|
}
|