@actuate-media/cli 0.4.1 → 0.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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +69 -12
- package/CHANGELOG.md +58 -0
- package/dist/__tests__/db-init.test.d.ts +2 -0
- package/dist/__tests__/db-init.test.d.ts.map +1 -0
- package/dist/__tests__/db-init.test.js +127 -0
- package/dist/__tests__/db-init.test.js.map +1 -0
- package/dist/__tests__/db-sync.test.d.ts +2 -0
- package/dist/__tests__/db-sync.test.d.ts.map +1 -0
- package/dist/__tests__/db-sync.test.js +136 -0
- package/dist/__tests__/db-sync.test.js.map +1 -0
- package/dist/__tests__/deployment-diagnostics.test.js.map +1 -1
- package/dist/__tests__/init.test.js.map +1 -1
- package/dist/__tests__/schema-fragment.test.js +1 -1
- package/dist/__tests__/schema-fragment.test.js.map +1 -1
- package/dist/__tests__/seed.test.js.map +1 -1
- package/dist/commands/db-init.d.ts +19 -2
- package/dist/commands/db-init.d.ts.map +1 -1
- package/dist/commands/db-init.js +128 -306
- package/dist/commands/db-init.js.map +1 -1
- package/dist/commands/db-status.d.ts +1 -1
- package/dist/commands/db-status.d.ts.map +1 -1
- package/dist/commands/db-status.js +33 -33
- package/dist/commands/db-status.js.map +1 -1
- package/dist/commands/db-sync.d.ts +31 -0
- package/dist/commands/db-sync.d.ts.map +1 -0
- package/dist/commands/db-sync.js +195 -0
- package/dist/commands/db-sync.js.map +1 -0
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +48 -41
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/export.d.ts +1 -1
- package/dist/commands/export.d.ts.map +1 -1
- package/dist/commands/export.js +32 -32
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/generate.d.ts +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +8 -8
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/import.d.ts +1 -1
- package/dist/commands/import.d.ts.map +1 -1
- package/dist/commands/import.js +55 -58
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/migrate.d.ts +1 -1
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +18 -24
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/seed.d.ts +1 -1
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/seed.js +156 -157
- package/dist/commands/seed.js.map +1 -1
- package/dist/commands/update-check.d.ts +1 -1
- package/dist/commands/update-check.d.ts.map +1 -1
- package/dist/commands/update-check.js +34 -27
- package/dist/commands/update-check.js.map +1 -1
- package/dist/commands/upgrade.d.ts +1 -1
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +46 -34
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/deployment/diagnostics.d.ts.map +1 -1
- package/dist/deployment/diagnostics.js +7 -2
- package/dist/deployment/diagnostics.js.map +1 -1
- package/dist/index.js +17 -15
- package/dist/index.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +5 -5
- package/dist/utils/logger.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/db-init.test.ts +155 -0
- package/src/__tests__/db-sync.test.ts +167 -0
- package/src/__tests__/deployment-diagnostics.test.ts +68 -60
- package/src/__tests__/init.test.ts +17 -17
- package/src/__tests__/schema-fragment.test.ts +29 -25
- package/src/__tests__/seed.test.ts +25 -25
- package/src/commands/db-init.ts +146 -319
- package/src/commands/db-status.ts +70 -68
- package/src/commands/db-sync.ts +227 -0
- package/src/commands/doctor.ts +102 -88
- package/src/commands/export.ts +65 -75
- package/src/commands/generate.ts +14 -16
- package/src/commands/import.ts +125 -140
- package/src/commands/init.ts +14 -14
- package/src/commands/migrate.ts +29 -35
- package/src/commands/seed.ts +294 -300
- package/src/commands/update-check.ts +77 -72
- package/src/commands/upgrade.ts +100 -85
- package/src/deployment/diagnostics.ts +86 -72
- package/src/index.ts +32 -30
- package/src/utils/logger.ts +10 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@actuate-media/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "CLI for Actuate CMS — migrations, codegen, imports, exports, and upgrades",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"typescript": "^5.7.0",
|
|
30
|
-
"vitest": "^
|
|
31
|
-
"@actuate-media/cms-core": "0.
|
|
30
|
+
"vitest": "^4.1.0",
|
|
31
|
+
"@actuate-media/cms-core": "0.51.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsc",
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
extractModelsFragment,
|
|
9
|
+
registerDbInitCommand,
|
|
10
|
+
resetCanonicalSchemaReader,
|
|
11
|
+
resetDbInitCommandRunner,
|
|
12
|
+
setCanonicalSchemaReader,
|
|
13
|
+
setDbInitCommandRunner,
|
|
14
|
+
} from '../commands/db-init.js'
|
|
15
|
+
|
|
16
|
+
const FULL_SCHEMA = `generator client {
|
|
17
|
+
provider = "prisma-client"
|
|
18
|
+
output = "../generated"
|
|
19
|
+
previewFeatures = ["relationJoins"]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
datasource db {
|
|
23
|
+
provider = "postgresql"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
enum DocumentStatus {
|
|
27
|
+
DRAFT
|
|
28
|
+
PUBLISHED
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
model Document {
|
|
32
|
+
id String @id @default(cuid())
|
|
33
|
+
collection String
|
|
34
|
+
status DocumentStatus @default(DRAFT)
|
|
35
|
+
|
|
36
|
+
@@index([collection])
|
|
37
|
+
@@map("actuate_documents")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
model User {
|
|
41
|
+
id String @id @default(cuid())
|
|
42
|
+
email String @unique
|
|
43
|
+
|
|
44
|
+
@@map("actuate_users")
|
|
45
|
+
}
|
|
46
|
+
`
|
|
47
|
+
|
|
48
|
+
function consumerSchema() {
|
|
49
|
+
return `generator client {
|
|
50
|
+
provider = "prisma-client-js"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
datasource db {
|
|
54
|
+
provider = "postgresql"
|
|
55
|
+
url = env("DATABASE_URL")
|
|
56
|
+
}
|
|
57
|
+
`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe('db:init (WS-D D5 — canonical schema, no stale fragment)', () => {
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
resetDbInitCommandRunner()
|
|
63
|
+
resetCanonicalSchemaReader()
|
|
64
|
+
vi.restoreAllMocks()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('extractModelsFragment', () => {
|
|
68
|
+
it('strips generator and datasource blocks but keeps enums + models', () => {
|
|
69
|
+
const fragment = extractModelsFragment(FULL_SCHEMA)
|
|
70
|
+
expect(fragment).not.toMatch(/generator\s+\w+\s*\{/)
|
|
71
|
+
expect(fragment).not.toMatch(/datasource\s+\w+\s*\{/)
|
|
72
|
+
expect(fragment).toContain('enum DocumentStatus')
|
|
73
|
+
expect(fragment).toContain('model Document')
|
|
74
|
+
expect(fragment).toContain('model User')
|
|
75
|
+
// The whole point of D5: real @@map names survive.
|
|
76
|
+
expect(fragment).toContain('@@map("actuate_documents")')
|
|
77
|
+
expect(fragment).toContain('@@map("actuate_users")')
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
describe('command', () => {
|
|
82
|
+
it('injects canonical models with @@map and no duplicate datasource/generator', async () => {
|
|
83
|
+
const tempRoot = await mkdtemp(path.join(tmpdir(), 'actuate-db-init-d5-'))
|
|
84
|
+
const schemaPath = path.join(tempRoot, 'schema.prisma')
|
|
85
|
+
await writeFile(schemaPath, consumerSchema())
|
|
86
|
+
|
|
87
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempRoot)
|
|
88
|
+
setDbInitCommandRunner(() => undefined)
|
|
89
|
+
setCanonicalSchemaReader(async () => FULL_SCHEMA)
|
|
90
|
+
|
|
91
|
+
const command = new Command()
|
|
92
|
+
registerDbInitCommand(command)
|
|
93
|
+
await command.parseAsync(['node', 'actuate', 'db:init', '--schema', 'schema.prisma'])
|
|
94
|
+
|
|
95
|
+
const result = await readFile(schemaPath, 'utf-8')
|
|
96
|
+
const injected = result.slice(result.indexOf('// ── Actuate CMS models'))
|
|
97
|
+
|
|
98
|
+
// The consumer keeps exactly one datasource/generator (their own).
|
|
99
|
+
expect(result.match(/datasource\s+\w+\s*\{/g)).toHaveLength(1)
|
|
100
|
+
expect(result.match(/generator\s+\w+\s*\{/g)).toHaveLength(1)
|
|
101
|
+
// Injected portion carries the canonical mapped models.
|
|
102
|
+
expect(injected).toContain('@@map("actuate_documents")')
|
|
103
|
+
expect(injected).toContain('model Document')
|
|
104
|
+
expect(injected).not.toMatch(/datasource\s+\w+\s*\{/)
|
|
105
|
+
|
|
106
|
+
await rm(tempRoot, { recursive: true, force: true })
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('fails clearly when cms-core cannot be located', async () => {
|
|
110
|
+
const tempRoot = await mkdtemp(path.join(tmpdir(), 'actuate-db-init-missing-'))
|
|
111
|
+
const schemaPath = path.join(tempRoot, 'schema.prisma')
|
|
112
|
+
await writeFile(schemaPath, consumerSchema())
|
|
113
|
+
|
|
114
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempRoot)
|
|
115
|
+
setDbInitCommandRunner(() => undefined)
|
|
116
|
+
setCanonicalSchemaReader(async () => null)
|
|
117
|
+
|
|
118
|
+
const command = new Command()
|
|
119
|
+
registerDbInitCommand(command)
|
|
120
|
+
await command.parseAsync(['node', 'actuate', 'db:init', '--schema', 'schema.prisma'])
|
|
121
|
+
|
|
122
|
+
// Schema must be left untouched (no stale fragment written).
|
|
123
|
+
const result = await readFile(schemaPath, 'utf-8')
|
|
124
|
+
expect(result).toBe(consumerSchema())
|
|
125
|
+
expect(process.exitCode).toBe(1)
|
|
126
|
+
process.exitCode = 0
|
|
127
|
+
|
|
128
|
+
await rm(tempRoot, { recursive: true, force: true })
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('is idempotent without --force', async () => {
|
|
132
|
+
const tempRoot = await mkdtemp(path.join(tmpdir(), 'actuate-db-init-idem-'))
|
|
133
|
+
const schemaPath = path.join(tempRoot, 'schema.prisma')
|
|
134
|
+
await writeFile(schemaPath, consumerSchema())
|
|
135
|
+
|
|
136
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempRoot)
|
|
137
|
+
setDbInitCommandRunner(() => undefined)
|
|
138
|
+
setCanonicalSchemaReader(async () => FULL_SCHEMA)
|
|
139
|
+
|
|
140
|
+
const command1 = new Command()
|
|
141
|
+
registerDbInitCommand(command1)
|
|
142
|
+
await command1.parseAsync(['node', 'actuate', 'db:init', '--schema', 'schema.prisma'])
|
|
143
|
+
const first = await readFile(schemaPath, 'utf-8')
|
|
144
|
+
|
|
145
|
+
const command2 = new Command()
|
|
146
|
+
registerDbInitCommand(command2)
|
|
147
|
+
await command2.parseAsync(['node', 'actuate', 'db:init', '--schema', 'schema.prisma'])
|
|
148
|
+
const second = await readFile(schemaPath, 'utf-8')
|
|
149
|
+
|
|
150
|
+
expect(second).toBe(first)
|
|
151
|
+
|
|
152
|
+
await rm(tempRoot, { recursive: true, force: true })
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
})
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { mkdtemp, mkdir, readFile, readdir, rm, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import { buildConsumerSchema, syncPrismaAssets } from '../commands/db-sync.js'
|
|
7
|
+
|
|
8
|
+
const CORE_SCHEMA = `generator client {
|
|
9
|
+
provider = "prisma-client"
|
|
10
|
+
output = "../generated"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
datasource db {
|
|
14
|
+
provider = "postgresql"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
enum DocumentStatus {
|
|
18
|
+
DRAFT
|
|
19
|
+
PUBLISHED
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
model User {
|
|
23
|
+
id String @id @default(cuid())
|
|
24
|
+
email String @unique
|
|
25
|
+
|
|
26
|
+
@@map("actuate_users")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
model Document {
|
|
30
|
+
id String @id @default(cuid())
|
|
31
|
+
status DocumentStatus @default(DRAFT)
|
|
32
|
+
|
|
33
|
+
@@map("actuate_documents")
|
|
34
|
+
}
|
|
35
|
+
`
|
|
36
|
+
|
|
37
|
+
async function makeCorePrismaDir(migrations: string[]): Promise<string> {
|
|
38
|
+
const dir = await mkdtemp(path.join(tmpdir(), 'core-prisma-'))
|
|
39
|
+
await writeFile(path.join(dir, 'schema.prisma'), CORE_SCHEMA)
|
|
40
|
+
const migrationsDir = path.join(dir, 'migrations')
|
|
41
|
+
await mkdir(migrationsDir, { recursive: true })
|
|
42
|
+
await writeFile(path.join(migrationsDir, 'migration_lock.toml'), 'provider = "postgresql"\n')
|
|
43
|
+
for (const m of migrations) {
|
|
44
|
+
await mkdir(path.join(migrationsDir, m), { recursive: true })
|
|
45
|
+
await writeFile(path.join(migrationsDir, m, 'migration.sql'), `-- ${m}\n`)
|
|
46
|
+
}
|
|
47
|
+
return dir
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('db:sync (WS-D D2 — post-upgrade schema sync)', () => {
|
|
51
|
+
const temps: string[] = []
|
|
52
|
+
afterEach(async () => {
|
|
53
|
+
await Promise.all(temps.map((t) => rm(t, { recursive: true, force: true })))
|
|
54
|
+
temps.length = 0
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
describe('buildConsumerSchema', () => {
|
|
58
|
+
it('strips cms-core generator/datasource and emits the consumer header', () => {
|
|
59
|
+
const schema = buildConsumerSchema(CORE_SCHEMA)
|
|
60
|
+
expect(schema).toContain('AUTO-SYNCED from @actuate-media/cms-core')
|
|
61
|
+
expect(schema).toContain('output = "../generated/prisma"')
|
|
62
|
+
// The cms-core generator output path must not leak through.
|
|
63
|
+
expect(schema).not.toContain('output = "../generated"')
|
|
64
|
+
// Exactly one datasource/generator (the consumer header).
|
|
65
|
+
expect(schema.match(/generator\s+\w+\s*\{/g)).toHaveLength(1)
|
|
66
|
+
expect(schema.match(/datasource\s+\w+\s*\{/g)).toHaveLength(1)
|
|
67
|
+
expect(schema).toContain('@@map("actuate_users")')
|
|
68
|
+
expect(schema).toContain('@@map("actuate_documents")')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('throws if the cms-core body lost its @@map names', () => {
|
|
72
|
+
const broken = CORE_SCHEMA.replace('@@map("actuate_users")', '')
|
|
73
|
+
expect(() => buildConsumerSchema(broken)).toThrow(/actuate_users/)
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('syncPrismaAssets', () => {
|
|
78
|
+
it('refreshes an auto-synced schema and adds missing migrations', async () => {
|
|
79
|
+
const coreDir = await makeCorePrismaDir(['0001_init', '0002_new'])
|
|
80
|
+
const projectDir = await mkdtemp(path.join(tmpdir(), 'consumer-'))
|
|
81
|
+
temps.push(coreDir, projectDir)
|
|
82
|
+
|
|
83
|
+
const prismaDir = path.join(projectDir, 'prisma')
|
|
84
|
+
await mkdir(path.join(prismaDir, 'migrations', '0001_init'), { recursive: true })
|
|
85
|
+
await writeFile(
|
|
86
|
+
path.join(prismaDir, 'migrations', '0001_init', 'migration.sql'),
|
|
87
|
+
'-- already here\n',
|
|
88
|
+
)
|
|
89
|
+
// An auto-synced (stale) schema.
|
|
90
|
+
await writeFile(
|
|
91
|
+
path.join(prismaDir, 'schema.prisma'),
|
|
92
|
+
'// AUTO-SYNCED from @actuate-media/cms-core\nmodel Old {}\n',
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
const result = await syncPrismaAssets(path.join(prismaDir, 'schema.prisma'), coreDir)
|
|
96
|
+
|
|
97
|
+
expect(result.schemaWritten).toBe(true)
|
|
98
|
+
expect(result.migrationsAdded).toEqual(['0002_new'])
|
|
99
|
+
expect(result.skippedReason).toBeUndefined()
|
|
100
|
+
|
|
101
|
+
const schema = await readFile(path.join(prismaDir, 'schema.prisma'), 'utf-8')
|
|
102
|
+
expect(schema).toContain('@@map("actuate_users")')
|
|
103
|
+
|
|
104
|
+
// The pre-existing migration is untouched (immutable history preserved).
|
|
105
|
+
const existing = await readFile(
|
|
106
|
+
path.join(prismaDir, 'migrations', '0001_init', 'migration.sql'),
|
|
107
|
+
'utf-8',
|
|
108
|
+
)
|
|
109
|
+
expect(existing).toBe('-- already here\n')
|
|
110
|
+
const dirs = (await readdir(path.join(prismaDir, 'migrations'), { withFileTypes: true }))
|
|
111
|
+
.filter((e) => e.isDirectory())
|
|
112
|
+
.map((e) => e.name)
|
|
113
|
+
.sort()
|
|
114
|
+
expect(dirs).toEqual(['0001_init', '0002_new'])
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('refuses to overwrite a customized (non-auto-synced) schema without --force', async () => {
|
|
118
|
+
const coreDir = await makeCorePrismaDir(['0001_init'])
|
|
119
|
+
const projectDir = await mkdtemp(path.join(tmpdir(), 'consumer-custom-'))
|
|
120
|
+
temps.push(coreDir, projectDir)
|
|
121
|
+
|
|
122
|
+
const schemaPath = path.join(projectDir, 'prisma', 'schema.prisma')
|
|
123
|
+
await mkdir(path.dirname(schemaPath), { recursive: true })
|
|
124
|
+
const custom = 'datasource db {\n provider = "postgresql"\n}\n\nmodel MyThing {}\n'
|
|
125
|
+
await writeFile(schemaPath, custom)
|
|
126
|
+
|
|
127
|
+
const result = await syncPrismaAssets(schemaPath, coreDir)
|
|
128
|
+
|
|
129
|
+
expect(result.schemaWritten).toBe(false)
|
|
130
|
+
expect(result.skippedReason).toMatch(/AUTO-SYNCED/)
|
|
131
|
+
// Custom schema untouched...
|
|
132
|
+
expect(await readFile(schemaPath, 'utf-8')).toBe(custom)
|
|
133
|
+
// ...but migrations are still synced additively.
|
|
134
|
+
expect(result.migrationsAdded).toEqual(['0001_init'])
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('overwrites a customized schema when --force is set', async () => {
|
|
138
|
+
const coreDir = await makeCorePrismaDir(['0001_init'])
|
|
139
|
+
const projectDir = await mkdtemp(path.join(tmpdir(), 'consumer-force-'))
|
|
140
|
+
temps.push(coreDir, projectDir)
|
|
141
|
+
|
|
142
|
+
const schemaPath = path.join(projectDir, 'prisma', 'schema.prisma')
|
|
143
|
+
await mkdir(path.dirname(schemaPath), { recursive: true })
|
|
144
|
+
await writeFile(schemaPath, 'model MyThing {}\n')
|
|
145
|
+
|
|
146
|
+
const result = await syncPrismaAssets(schemaPath, coreDir, { force: true })
|
|
147
|
+
|
|
148
|
+
expect(result.schemaWritten).toBe(true)
|
|
149
|
+
expect(await readFile(schemaPath, 'utf-8')).toContain('@@map("actuate_users")')
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('is idempotent — a second run writes nothing', async () => {
|
|
153
|
+
const coreDir = await makeCorePrismaDir(['0001_init'])
|
|
154
|
+
const projectDir = await mkdtemp(path.join(tmpdir(), 'consumer-idem-'))
|
|
155
|
+
temps.push(coreDir, projectDir)
|
|
156
|
+
|
|
157
|
+
const schemaPath = path.join(projectDir, 'prisma', 'schema.prisma')
|
|
158
|
+
const first = await syncPrismaAssets(schemaPath, coreDir)
|
|
159
|
+
expect(first.schemaWritten).toBe(true)
|
|
160
|
+
expect(first.migrationsAdded).toEqual(['0001_init'])
|
|
161
|
+
|
|
162
|
+
const second = await syncPrismaAssets(schemaPath, coreDir)
|
|
163
|
+
expect(second.schemaWritten).toBe(false)
|
|
164
|
+
expect(second.migrationsAdded).toEqual([])
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
})
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
buildDeploymentManifest,
|
|
5
5
|
createDiagnosticReport,
|
|
6
6
|
REQUIRED_CMS_MODELS,
|
|
7
7
|
REQUIRED_ENV_VARS,
|
|
8
|
-
} from '../deployment/diagnostics.js'
|
|
8
|
+
} from '../deployment/diagnostics.js'
|
|
9
9
|
|
|
10
10
|
describe('deployment diagnostics', () => {
|
|
11
11
|
it('tracks deploy-critical models used by first-run admin features', () => {
|
|
12
|
-
expect(REQUIRED_CMS_MODELS).toEqual(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
expect(REQUIRED_CMS_MODELS).toEqual(
|
|
13
|
+
expect.arrayContaining([
|
|
14
|
+
'User',
|
|
15
|
+
'Session',
|
|
16
|
+
'Document',
|
|
17
|
+
'Media',
|
|
18
|
+
'Version',
|
|
19
|
+
'Folder',
|
|
20
|
+
'Redirect',
|
|
21
|
+
'FormSubmission',
|
|
22
|
+
'AuditLog',
|
|
23
|
+
'PasswordResetToken',
|
|
24
|
+
'MediaUsage',
|
|
25
|
+
'ScriptTag',
|
|
26
|
+
'PageTemplate',
|
|
27
|
+
'SavedSection',
|
|
28
|
+
]),
|
|
29
|
+
)
|
|
30
|
+
})
|
|
29
31
|
|
|
30
32
|
it('reports missing models and env vars with exact fix commands', () => {
|
|
31
33
|
const report = createDiagnosticReport({
|
|
@@ -36,22 +38,24 @@ describe('deployment diagnostics', () => {
|
|
|
36
38
|
},
|
|
37
39
|
packageManager: 'pnpm',
|
|
38
40
|
schemaPath: 'prisma/schema.prisma',
|
|
39
|
-
})
|
|
41
|
+
})
|
|
40
42
|
|
|
41
|
-
expect(report.status).toBe('fail')
|
|
42
|
-
expect(report.checks).toEqual(
|
|
43
|
-
expect.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
expect(report.status).toBe('fail')
|
|
44
|
+
expect(report.checks).toEqual(
|
|
45
|
+
expect.arrayContaining([
|
|
46
|
+
expect.objectContaining({
|
|
47
|
+
id: 'schema-models',
|
|
48
|
+
status: 'fail',
|
|
49
|
+
fix: 'Run `actuate db:init --schema prisma/schema.prisma` for new schemas, or update the existing Actuate block from the database setup docs, then create and apply a Prisma migration.',
|
|
50
|
+
}),
|
|
51
|
+
expect.objectContaining({
|
|
52
|
+
id: 'environment',
|
|
53
|
+
status: 'fail',
|
|
54
|
+
fix: 'Set missing environment variables before deploying: CMS_SECRET, CMS_ENCRYPTION_KEY, NEXT_PUBLIC_SITE_URL.',
|
|
55
|
+
}),
|
|
56
|
+
]),
|
|
57
|
+
)
|
|
58
|
+
})
|
|
55
59
|
|
|
56
60
|
it('requires migration connection details for deploy checks', () => {
|
|
57
61
|
const report = createDiagnosticReport({
|
|
@@ -66,16 +70,18 @@ describe('deployment diagnostics', () => {
|
|
|
66
70
|
packageManager: 'pnpm',
|
|
67
71
|
schemaPath: 'prisma/schema.prisma',
|
|
68
72
|
mode: 'deploy',
|
|
69
|
-
})
|
|
73
|
+
})
|
|
70
74
|
|
|
71
|
-
expect(report.status).toBe('fail')
|
|
72
|
-
expect(report.checks).toEqual(
|
|
73
|
-
expect.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
expect(report.status).toBe('fail')
|
|
76
|
+
expect(report.checks).toEqual(
|
|
77
|
+
expect.arrayContaining([
|
|
78
|
+
expect.objectContaining({
|
|
79
|
+
id: 'environment',
|
|
80
|
+
message: expect.stringContaining('DIRECT_DATABASE_URL'),
|
|
81
|
+
}),
|
|
82
|
+
]),
|
|
83
|
+
)
|
|
84
|
+
})
|
|
79
85
|
|
|
80
86
|
it('warns when designed marketing pages appear to use flat fields instead of page-builder content', () => {
|
|
81
87
|
const report = createDiagnosticReport({
|
|
@@ -107,24 +113,26 @@ describe('deployment diagnostics', () => {
|
|
|
107
113
|
},
|
|
108
114
|
packageManager: 'pnpm',
|
|
109
115
|
schemaPath: 'prisma/schema.prisma',
|
|
110
|
-
})
|
|
116
|
+
})
|
|
111
117
|
|
|
112
|
-
expect(report.status).toBe('warn')
|
|
113
|
-
expect(report.checks).toEqual(
|
|
114
|
-
expect.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
expect(report.status).toBe('warn')
|
|
119
|
+
expect(report.checks).toEqual(
|
|
120
|
+
expect.arrayContaining([
|
|
121
|
+
expect.objectContaining({
|
|
122
|
+
id: 'design-first-page-builder',
|
|
123
|
+
status: 'warn',
|
|
124
|
+
docs: 'https://actuatecms.dev/docs/design-first-page-builder',
|
|
125
|
+
}),
|
|
126
|
+
]),
|
|
127
|
+
)
|
|
128
|
+
})
|
|
121
129
|
|
|
122
130
|
it('exposes machine-readable deployment metadata', () => {
|
|
123
|
-
const manifest = buildDeploymentManifest()
|
|
131
|
+
const manifest = buildDeploymentManifest()
|
|
124
132
|
|
|
125
|
-
expect(manifest.requiredModels).toEqual(REQUIRED_CMS_MODELS)
|
|
126
|
-
expect(manifest.requiredEnv).toEqual(REQUIRED_ENV_VARS)
|
|
127
|
-
expect(manifest.routes.apiHealth).toBe('/api/cms/health')
|
|
128
|
-
expect(manifest.crons.scheduledPublish).toBe('/api/cms/cron/publish')
|
|
129
|
-
})
|
|
130
|
-
})
|
|
133
|
+
expect(manifest.requiredModels).toEqual(REQUIRED_CMS_MODELS)
|
|
134
|
+
expect(manifest.requiredEnv).toEqual(REQUIRED_ENV_VARS)
|
|
135
|
+
expect(manifest.routes.apiHealth).toBe('/api/cms/health')
|
|
136
|
+
expect(manifest.crons.scheduledPublish).toBe('/api/cms/cron/publish')
|
|
137
|
+
})
|
|
138
|
+
})
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises'
|
|
2
|
-
import { Command } from 'commander'
|
|
3
|
-
import { describe, expect, it } from 'vitest'
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { Command } from 'commander'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
4
|
|
|
5
|
-
import { buildCreateActuateArgs, registerInitCommand } from '../commands/init.js'
|
|
5
|
+
import { buildCreateActuateArgs, registerInitCommand } from '../commands/init.js'
|
|
6
6
|
|
|
7
7
|
describe('init command', () => {
|
|
8
8
|
it('registers an init command that delegates to create-actuate-cms', () => {
|
|
9
|
-
const program = new Command()
|
|
10
|
-
registerInitCommand(program)
|
|
9
|
+
const program = new Command()
|
|
10
|
+
registerInitCommand(program)
|
|
11
11
|
|
|
12
|
-
const command = program.commands.find((candidate) => candidate.name() === 'init')
|
|
12
|
+
const command = program.commands.find((candidate) => candidate.name() === 'init')
|
|
13
13
|
|
|
14
|
-
expect(command).toBeDefined()
|
|
15
|
-
expect(buildCreateActuateArgs()).toEqual(['create', 'actuate-cms@latest'])
|
|
14
|
+
expect(command).toBeDefined()
|
|
15
|
+
expect(buildCreateActuateArgs()).toEqual(['create', 'actuate-cms@latest'])
|
|
16
16
|
expect(buildCreateActuateArgs('maidpro-site')).toEqual([
|
|
17
17
|
'create',
|
|
18
18
|
'actuate-cms@latest',
|
|
19
19
|
'maidpro-site',
|
|
20
|
-
])
|
|
21
|
-
})
|
|
20
|
+
])
|
|
21
|
+
})
|
|
22
22
|
|
|
23
23
|
it('exposes an actuate-cms bin alias for installed CLI usage', async () => {
|
|
24
|
-
const raw = await readFile(new URL('../../package.json', import.meta.url), 'utf-8')
|
|
25
|
-
const pkg = JSON.parse(raw) as { bin?: Record<string, string> }
|
|
24
|
+
const raw = await readFile(new URL('../../package.json', import.meta.url), 'utf-8')
|
|
25
|
+
const pkg = JSON.parse(raw) as { bin?: Record<string, string> }
|
|
26
26
|
|
|
27
|
-
expect(pkg.bin?.actuate).toBe('dist/index.js')
|
|
28
|
-
expect(pkg.bin?.['actuate-cms']).toBe('dist/index.js')
|
|
29
|
-
})
|
|
30
|
-
})
|
|
27
|
+
expect(pkg.bin?.actuate).toBe('dist/index.js')
|
|
28
|
+
expect(pkg.bin?.['actuate-cms']).toBe('dist/index.js')
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { Command } from 'commander'
|
|
2
|
-
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
3
|
-
import { tmpdir } from 'node:os'
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
registerDbInitCommand,
|
|
9
|
+
resetDbInitCommandRunner,
|
|
10
|
+
setDbInitCommandRunner,
|
|
11
|
+
} from '../commands/db-init.js'
|
|
12
|
+
import { REQUIRED_CMS_MODELS } from '../deployment/diagnostics.js'
|
|
9
13
|
|
|
10
14
|
function baseSchema() {
|
|
11
15
|
return `generator client {
|
|
@@ -16,32 +20,32 @@ datasource db {
|
|
|
16
20
|
provider = "postgresql"
|
|
17
21
|
url = env("DATABASE_URL")
|
|
18
22
|
}
|
|
19
|
-
|
|
23
|
+
`
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
describe('db:init schema fragment', () => {
|
|
23
27
|
afterEach(() => {
|
|
24
|
-
resetDbInitCommandRunner()
|
|
25
|
-
vi.restoreAllMocks()
|
|
26
|
-
})
|
|
28
|
+
resetDbInitCommandRunner()
|
|
29
|
+
vi.restoreAllMocks()
|
|
30
|
+
})
|
|
27
31
|
|
|
28
32
|
it('injects all deploy-critical Actuate models', async () => {
|
|
29
|
-
const tempRoot = await mkdtemp(path.join(tmpdir(), 'actuate-db-init-'))
|
|
30
|
-
const schemaPath = path.join(tempRoot, 'schema.prisma')
|
|
31
|
-
await writeFile(schemaPath, baseSchema())
|
|
33
|
+
const tempRoot = await mkdtemp(path.join(tmpdir(), 'actuate-db-init-'))
|
|
34
|
+
const schemaPath = path.join(tempRoot, 'schema.prisma')
|
|
35
|
+
await writeFile(schemaPath, baseSchema())
|
|
32
36
|
|
|
33
|
-
vi.spyOn(process, 'cwd').mockReturnValue(tempRoot)
|
|
34
|
-
setDbInitCommandRunner(() => undefined)
|
|
35
|
-
const command = new Command()
|
|
36
|
-
registerDbInitCommand(command)
|
|
37
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempRoot)
|
|
38
|
+
setDbInitCommandRunner(() => undefined)
|
|
39
|
+
const command = new Command()
|
|
40
|
+
registerDbInitCommand(command)
|
|
37
41
|
|
|
38
|
-
await command.parseAsync(['node', 'actuate', 'db:init', '--schema', 'schema.prisma'])
|
|
42
|
+
await command.parseAsync(['node', 'actuate', 'db:init', '--schema', 'schema.prisma'])
|
|
39
43
|
|
|
40
|
-
const schema = await readFile(schemaPath, 'utf-8')
|
|
44
|
+
const schema = await readFile(schemaPath, 'utf-8')
|
|
41
45
|
for (const model of REQUIRED_CMS_MODELS) {
|
|
42
|
-
expect(schema).toContain(`model ${model} `)
|
|
46
|
+
expect(schema).toContain(`model ${model} `)
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
await rm(tempRoot, { recursive: true, force: true })
|
|
46
|
-
})
|
|
47
|
-
})
|
|
49
|
+
await rm(tempRoot, { recursive: true, force: true })
|
|
50
|
+
})
|
|
51
|
+
})
|