@contember/engine-system-api 1.2.0-alpha.18 → 1.2.0-alpha.19
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/src/migrations/2020-05-06-150000-composed-primary.d.ts +1 -1
- package/dist/src/migrations/2020-05-06-150000-composed-primary.d.ts.map +1 -1
- package/dist/src/migrations/2020-06-01-103000-event-trigger-perf.d.ts +1 -1
- package/dist/src/migrations/2020-06-01-103000-event-trigger-perf.d.ts.map +1 -1
- package/dist/src/migrations/2021-05-07-155800-event-log-rework.d.ts +1 -1
- package/dist/src/migrations/2021-05-07-155800-event-log-rework.d.ts.map +1 -1
- package/dist/src/model/ProjectInitializer.d.ts.map +1 -1
- package/dist/src/model/ProjectInitializer.js +1 -2
- package/dist/src/model/ProjectInitializer.js.map +1 -1
- package/dist/src/model/migrations/ProjectMigrator.d.ts.map +1 -1
- package/dist/src/model/migrations/ProjectMigrator.js +8 -2
- package/dist/src/model/migrations/ProjectMigrator.js.map +1 -1
- package/dist/src/model/queries/events/LatestTransactionIdByStageQuery.d.ts +2 -2
- package/dist/src/model/queries/events/LatestTransactionIdByStageQuery.d.ts.map +1 -1
- package/dist/src/model/queries/events/LatestTransactionIdByStageQuery.js +9 -14
- package/dist/src/model/queries/events/LatestTransactionIdByStageQuery.js.map +1 -1
- package/dist/src/schema/system.graphql.d.ts.map +1 -1
- package/dist/src/schema/system.graphql.js +6 -0
- package/dist/src/schema/system.graphql.js.map +1 -1
- package/dist/src/schema/types.d.ts +7 -0
- package/dist/src/schema/types.d.ts.map +1 -1
- package/dist/src/schema/types.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -13
- package/src/migrations/2020-05-06-150000-composed-primary.ts +1 -1
- package/src/migrations/2020-06-01-103000-event-trigger-perf.ts +1 -1
- package/src/migrations/2021-05-07-155800-event-log-rework.ts +1 -1
- package/src/model/ProjectInitializer.ts +1 -2
- package/src/model/migrations/ProjectMigrator.ts +11 -2
- package/src/model/queries/events/LatestTransactionIdByStageQuery.ts +10 -24
- package/src/schema/system.graphql.ts +6 -0
- package/src/schema/types.ts +8 -0
- package/src/tsconfig.json +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-system-api",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.19",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src/index.d.ts",
|
|
@@ -9,22 +9,23 @@
|
|
|
9
9
|
"test": "vitest"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@contember/authorization": "^1.2.0-alpha.
|
|
13
|
-
"@contember/database": "^1.2.0-alpha.
|
|
14
|
-
"@contember/database-migrations": "^1.2.0-alpha.
|
|
15
|
-
"@contember/dic": "^1.2.0-alpha.
|
|
16
|
-
"@contember/engine-common": "^1.2.0-alpha.
|
|
17
|
-
"@contember/graphql-utils": "^1.2.0-alpha.
|
|
18
|
-
"@contember/
|
|
19
|
-
"@contember/
|
|
20
|
-
"@contember/schema
|
|
21
|
-
"@contember/schema-
|
|
12
|
+
"@contember/authorization": "^1.2.0-alpha.19",
|
|
13
|
+
"@contember/database": "^1.2.0-alpha.19",
|
|
14
|
+
"@contember/database-migrations": "^1.2.0-alpha.19",
|
|
15
|
+
"@contember/dic": "^1.2.0-alpha.19",
|
|
16
|
+
"@contember/engine-common": "^1.2.0-alpha.19",
|
|
17
|
+
"@contember/graphql-utils": "^1.2.0-alpha.19",
|
|
18
|
+
"@contember/logger": "^1.2.0-alpha.19",
|
|
19
|
+
"@contember/queryable": "^1.2.0-alpha.19",
|
|
20
|
+
"@contember/schema": "^1.2.0-alpha.19",
|
|
21
|
+
"@contember/schema-migrations": "^1.2.0-alpha.19",
|
|
22
|
+
"@contember/schema-utils": "^1.2.0-alpha.19",
|
|
22
23
|
"@graphql-tools/utils": "^8.6.13",
|
|
23
24
|
"graphql-tag": "^2.12.5"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@contember/engine-api-tester": "^1.2.0-alpha.
|
|
27
|
-
"@contember/schema-definition": "^1.2.0-alpha.
|
|
27
|
+
"@contember/engine-api-tester": "^1.2.0-alpha.19",
|
|
28
|
+
"@contember/schema-definition": "^1.2.0-alpha.19",
|
|
28
29
|
"@graphql-codegen/cli": "^2.6.2",
|
|
29
30
|
"@graphql-codegen/typescript": "^2.5.1",
|
|
30
31
|
"@graphql-codegen/typescript-operations": "^2.4.2",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { escapeValue, MigrationBuilder, Name } from '@contember/database-migrations'
|
|
2
2
|
import { SystemMigrationArgs } from './types'
|
|
3
3
|
import { getJunctionTables } from '../model'
|
|
4
|
-
import { MigrationArgs } from '@contember/database-migrations
|
|
4
|
+
import { MigrationArgs } from '@contember/database-migrations'
|
|
5
5
|
|
|
6
6
|
const createEventTrigger = (builder: MigrationBuilder, tableName: Name, primaryColumns: string[]) => {
|
|
7
7
|
builder.createTrigger(tableName, 'log_event', {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MigrationBuilder, Name } from '@contember/database-migrations'
|
|
2
2
|
import { SystemMigrationArgs } from './types'
|
|
3
3
|
import { getJunctionTables } from '../model'
|
|
4
|
-
import { MigrationArgs } from '@contember/database-migrations
|
|
4
|
+
import { MigrationArgs } from '@contember/database-migrations'
|
|
5
5
|
|
|
6
6
|
const createEventStatementTrigger = (builder: MigrationBuilder, tableName: Name) => {
|
|
7
7
|
builder.createTrigger(tableName, 'log_event_statement', {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MigrationBuilder, Name } from '@contember/database-migrations'
|
|
2
2
|
import { SystemMigrationArgs } from './types'
|
|
3
3
|
import { getJunctionTables } from '../model'
|
|
4
|
-
import { MigrationArgs } from '@contember/database-migrations
|
|
4
|
+
import { MigrationArgs } from '@contember/database-migrations'
|
|
5
5
|
|
|
6
6
|
const createTrxEvent = (builder: MigrationBuilder, tableName: Name) => {
|
|
7
7
|
builder.createTrigger(tableName, 'log_event_trx', {
|
|
@@ -32,8 +32,7 @@ export class ProjectInitializer {
|
|
|
32
32
|
// todo: use dbContext
|
|
33
33
|
initLogger.debug('Executing system schema migrations')
|
|
34
34
|
await createDatabaseIfNotExists(project.db, message => typeof message === 'string' ? initLogger.warn(message) : initLogger.error(message))
|
|
35
|
-
const singleConnection = Connection.createSingle(project.db, err => initLogger.error(err))
|
|
36
|
-
singleConnection.eventManager.on(EventManager.Event.clientError, err => logger.error(err, { message: 'Database client error' }))
|
|
35
|
+
const singleConnection = Connection.createSingle(project.db, err => initLogger.error(err, { message: 'Database client error' }))
|
|
37
36
|
|
|
38
37
|
await singleConnection.scope(async connection => {
|
|
39
38
|
const systemSchema = dbContext.client.schema
|
|
@@ -82,16 +82,25 @@ export class ProjectMigrator {
|
|
|
82
82
|
}
|
|
83
83
|
const latestModification = described[described.length - 1]
|
|
84
84
|
schema = latestModification.schema
|
|
85
|
-
const errors = SchemaValidator.validate(schema)
|
|
85
|
+
const errors = SchemaValidator.validate(schema, migration.skippedErrors)
|
|
86
86
|
if (errors.length > 0) {
|
|
87
87
|
throw new InvalidSchemaError(
|
|
88
88
|
migration.version,
|
|
89
89
|
'Migration generates invalid schema: \n' +
|
|
90
|
-
errors.map(it => it.path.join('.')
|
|
90
|
+
errors.map(it => `${it.path.join('.')}: [${it.code}] ${it.message}`).join('\n'),
|
|
91
91
|
)
|
|
92
92
|
}
|
|
93
93
|
toExecute.push(migration)
|
|
94
94
|
}
|
|
95
|
+
// intentionally not using skippedErrors here
|
|
96
|
+
const errors = SchemaValidator.validate(schema)
|
|
97
|
+
if (errors.length > 0) {
|
|
98
|
+
throw new InvalidSchemaError(
|
|
99
|
+
toExecute[toExecute.length - 1].version,
|
|
100
|
+
'Migration generates invalid schema: \n' +
|
|
101
|
+
errors.map(it => it.path.join('.') + ': ' + it.message).join('\n'),
|
|
102
|
+
)
|
|
103
|
+
}
|
|
95
104
|
return toExecute
|
|
96
105
|
}
|
|
97
106
|
|
|
@@ -1,34 +1,20 @@
|
|
|
1
|
-
import { DatabaseQuery, DatabaseQueryable } from '@contember/database'
|
|
1
|
+
import { DatabaseQuery, DatabaseQueryable, SelectBuilder } from '@contember/database'
|
|
2
2
|
import { ImplementationException } from '../../../utils'
|
|
3
3
|
|
|
4
4
|
export class LatestTransactionIdByStageQuery extends DatabaseQuery<string> {
|
|
5
|
-
constructor(private readonly
|
|
5
|
+
constructor(private readonly stageId: string) {
|
|
6
6
|
super()
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
async fetch(queryable: DatabaseQueryable): Promise<string> {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
19
|
-
).rows[0].id
|
|
20
|
-
const rows = (
|
|
21
|
-
await queryable.db.query<{ transaction_id: string }>(
|
|
22
|
-
`
|
|
23
|
-
SELECT transaction_id
|
|
24
|
-
FROM system.stage_transaction
|
|
25
|
-
WHERE stage_id = ?
|
|
26
|
-
ORDER BY applied_at DESC
|
|
27
|
-
LIMIT 1
|
|
28
|
-
`,
|
|
29
|
-
[stageId],
|
|
30
|
-
)
|
|
31
|
-
).rows
|
|
10
|
+
const rows = await SelectBuilder.create<{ transaction_id: string }>()
|
|
11
|
+
.from('stage_transaction')
|
|
12
|
+
.select('transaction_id')
|
|
13
|
+
.where({ stage_id: this.stageId })
|
|
14
|
+
.orderBy('applied_at', 'desc')
|
|
15
|
+
.limit(1)
|
|
16
|
+
.getResult(queryable.db)
|
|
17
|
+
|
|
32
18
|
if (rows.length !== 1) {
|
|
33
19
|
throw new ImplementationException()
|
|
34
20
|
}
|
|
@@ -139,6 +139,12 @@ const schema: DocumentNode = gql`
|
|
|
139
139
|
name: String!
|
|
140
140
|
formatVersion: Int!
|
|
141
141
|
modifications: [Json!]!
|
|
142
|
+
skippedErrors: [MigrationSkippedError!]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
input MigrationSkippedError {
|
|
146
|
+
code: String!
|
|
147
|
+
path: String
|
|
142
148
|
}
|
|
143
149
|
|
|
144
150
|
enum MigrateErrorCode {
|
package/src/schema/types.ts
CHANGED
|
@@ -145,6 +145,7 @@ export type Migration = {
|
|
|
145
145
|
readonly formatVersion: Scalars['Int']
|
|
146
146
|
readonly modifications: ReadonlyArray<Scalars['Json']>
|
|
147
147
|
readonly name: Scalars['String']
|
|
148
|
+
readonly skippedErrors?: InputMaybe<ReadonlyArray<MigrationSkippedError>>
|
|
148
149
|
readonly version: Scalars['String']
|
|
149
150
|
}
|
|
150
151
|
|
|
@@ -188,6 +189,11 @@ export type MigrationModifyResponse = {
|
|
|
188
189
|
readonly ok: Scalars['Boolean']
|
|
189
190
|
}
|
|
190
191
|
|
|
192
|
+
export type MigrationSkippedError = {
|
|
193
|
+
readonly code: Scalars['String']
|
|
194
|
+
readonly path?: InputMaybe<Scalars['String']>
|
|
195
|
+
}
|
|
196
|
+
|
|
191
197
|
export type Mutation = {
|
|
192
198
|
readonly __typename?: 'Mutation'
|
|
193
199
|
readonly forceMigrate: MigrateResponse
|
|
@@ -358,6 +364,7 @@ export type ResolversTypes = {
|
|
|
358
364
|
MigrationModifyError: ResolverTypeWrapper<MigrationModifyError>
|
|
359
365
|
MigrationModifyErrorCode: MigrationModifyErrorCode
|
|
360
366
|
MigrationModifyResponse: ResolverTypeWrapper<MigrationModifyResponse>
|
|
367
|
+
MigrationSkippedError: MigrationSkippedError
|
|
361
368
|
Mutation: ResolverTypeWrapper<{}>
|
|
362
369
|
PrimaryKey: ResolverTypeWrapper<Scalars['PrimaryKey']>
|
|
363
370
|
Query: ResolverTypeWrapper<{}>
|
|
@@ -390,6 +397,7 @@ export type ResolversParentTypes = {
|
|
|
390
397
|
MigrationModification: MigrationModification
|
|
391
398
|
MigrationModifyError: MigrationModifyError
|
|
392
399
|
MigrationModifyResponse: MigrationModifyResponse
|
|
400
|
+
MigrationSkippedError: MigrationSkippedError
|
|
393
401
|
Mutation: {}
|
|
394
402
|
PrimaryKey: Scalars['PrimaryKey']
|
|
395
403
|
Query: {}
|
package/src/tsconfig.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
},
|
|
7
7
|
"references": [
|
|
8
8
|
{
|
|
9
|
-
"path": "../../
|
|
9
|
+
"path": "../../authorization/src"
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
"path": "../../database/src"
|
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
{
|
|
15
15
|
"path": "../../database-migrations/src"
|
|
16
16
|
},
|
|
17
|
-
{
|
|
18
|
-
"path": "../../authorization/src"
|
|
19
|
-
},
|
|
20
17
|
{
|
|
21
18
|
"path": "../../engine-common/src"
|
|
22
19
|
},
|
|
23
20
|
{
|
|
24
21
|
"path": "../../graphql-utils/src"
|
|
25
22
|
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../logger/src"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../../queryable/src"
|
|
28
|
+
},
|
|
26
29
|
{
|
|
27
30
|
"path": "../../schema/src"
|
|
28
31
|
},
|