Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
7675af3
feat: initial db pull implementation
svetch Sep 23, 2025
5652448
fix: generate imports and attributes for zmodel-code-generator
svetch Sep 24, 2025
6b16564
fix: add option to not exclude imports in loadDocument
svetch Sep 24, 2025
b13e15f
fix: continue work on db pull
svetch Sep 24, 2025
585b5cd
fix: missing import
svetch Sep 24, 2025
3c92894
fix: rewrite model generation
svetch Sep 26, 2025
eb8b682
feat: add ast factory
svetch Oct 5, 2025
126bdcf
fix: ast factory import order
svetch Oct 5, 2025
4914bae
fix: some runtime bugs
svetch Oct 6, 2025
3bd3336
fix: lint fix
svetch Oct 20, 2025
b1633eb
fix: update zmodel code generator
svetch Oct 20, 2025
3e398ba
feat: add exclude schemas option
svetch Oct 20, 2025
877d3a5
feat: implement initial diff update
svetch Oct 20, 2025
2f90d8f
fix: update format in zmodel code generator
svetch Oct 20, 2025
ed94090
fix: typo
svetch Oct 20, 2025
04235d9
feat: progress on database introspection and syncing
svetch Oct 21, 2025
00a1d78
fix: make ignore behave it does in prisma with no index models
svetch Oct 21, 2025
b4708fe
fix: lint fix
svetch Oct 21, 2025
f946726
feat: make all format options configurable
svetch Oct 21, 2025
75ce687
fix: lint fix
svetch Oct 21, 2025
9063c72
feat: Handle the database type mapping
svetch Oct 22, 2025
e7290ce
fix: catch up with feature updates
svetch Nov 12, 2025
83c2776
fix: add sqlite e2e test and fix some bugs
svetch Nov 21, 2025
a420199
fix: lint fix
svetch Nov 21, 2025
73d67b6
fix: formatting for e2e test schemas
svetch Nov 21, 2025
d1aac0f
test: run db pull e2e test also for postgres
svetch Nov 21, 2025
426feb0
fix: postgres instorspection schema filter
svetch Nov 23, 2025
8651f68
test: update cli tests
svetch Nov 23, 2025
7e2f17d
feat(cli): Improves database introspection and syncing
svetch Dec 15, 2025
ea364d2
fix(cli): fixes field casing and sort issues
svetch Jan 9, 2026
5b07e8f
chore(cli): remove temporary test script
svetch Jan 27, 2026
be99621
chore: update pnpm-lock.yaml
svetch Jan 27, 2026
2e4c249
feat(cli): add MySQL support for schema introspection
svetch Jan 27, 2026
71717a5
fix(cli): improve field matching logic during db pull
svetch Jan 27, 2026
e5de3a0
feat(cli): enhance SQLite introspection with autoincrement support
svetch Jan 27, 2026
52877c3
fix(cli): refine attribute generation in db pull
svetch Jan 27, 2026
cf74d8b
test(cli): update db pull tests for SQLite specific behavior
svetch Jan 27, 2026
fc9b360
refactor(language): export ZModelServices type
svetch Jan 27, 2026
459b970
fix(cli): improve sqlite introspection for autoincrement and fk names
svetch Jan 28, 2026
dbb1df2
feat(cli): enhance field matching logic during pull by using relation…
svetch Jan 28, 2026
47d0273
refactor(cli): refine relation name generation and table syncing
svetch Jan 28, 2026
e318ff4
test(cli): update pull tests to reflect improved schema generation
svetch Jan 28, 2026
c5d87f0
test(cli): add MySQL support to test utility helpers
svetch Jan 28, 2026
f0cfebb
fix(cli): omit default constraint names in table sync
svetch Jan 28, 2026
f0d408b
fix: correctly handle default values for 'text' type in PostgreSQL
svetch Jan 28, 2026
b9e2840
fix: sort table indexes to ensure stable schema generation
svetch Jan 28, 2026
66c0afb
refactor: dynamically determine supported db providers in CLI
svetch Jan 28, 2026
057407c
test: fix typo in pull test description
svetch Jan 28, 2026
6c542c5
chore(cli): remove debug artifacts and silence test logs
svetch Jan 28, 2026
c236ba8
fix(cli): ensure MySQL column and index ordering
svetch Jan 29, 2026
6fe2df4
fix(cli): preserve column order during MySQL pull
svetch Jan 30, 2026
3f983d2
refactor(cli): remove schema fields from MySQL queries
svetch Jan 30, 2026
769864a
fix(cli): improve MySQL introspection and index mapping
svetch Jan 30, 2026
336660e
test(cli): pass provider to default prelude in tests
svetch Jan 30, 2026
52d32c8
fix(cli): improve MySQL introspection for types and defaults
svetch Jan 30, 2026
2f7fe79
fix(cli): improve MySQL default value introspection
svetch Jan 30, 2026
52f1ffa
test(cli): expand and reorganize db pull tests
svetch Jan 30, 2026
381b1d2
refactor: restructure introspection provider interface and attribute …
svetch Jan 30, 2026
34da2df
feat: modernize MySQL introspection provider
svetch Jan 30, 2026
07c5804
feat: modernize PostgreSQL introspection provider
svetch Jan 30, 2026
9450535
feat: modernize SQLite introspection provider
svetch Jan 30, 2026
7a5071b
fix: improve relation field naming and default action handling
svetch Jan 30, 2026
7910c09
feat: track imports and auto-format during db pull
svetch Jan 30, 2026
7c30225
test: update pull tests to reflect naming and formatting improvements
svetch Jan 30, 2026
0f999b6
fix(cli): refactor PostgreSQL type casting and fix index order
svetch Jan 30, 2026
c1e717d
fix(cli): filter out auto-generated MySQL indexes
svetch Jan 30, 2026
27c40bd
test(cli): support datasource extras in test utils
svetch Jan 30, 2026
9b54b5f
fix: address PR comments
svetch Jan 30, 2026
3c48a17
fix: address PR comments
svetch Feb 3, 2026
5dc900e
fix: address PR comments
svetch Feb 3, 2026
a3c5d62
fix: address PR comments
svetch Feb 3, 2026
cea210d
fix(cli): improve file path resolution in pull action
svetch Feb 6, 2026
b68e9ab
refactor(cli): extract and enhance name casing logic
svetch Feb 6, 2026
3f0b6f2
refactor(cli): consolidate default value normalization
svetch Feb 6, 2026
d03c2bc
feat(cli): improve enum syncing and relation naming during pull
svetch Feb 6, 2026
2922d6b
docs(cli): add documentation comments to SQL introspection queries
svetch Feb 6, 2026
62cdd73
test(cli): refactor test utilities and modernize test suites
svetch Feb 6, 2026
06dd907
fix(cli): improve db pull for composite FKs and MySQL uniqueness
svetch Feb 6, 2026
7436243
fix: address PR comments
svetch Feb 6, 2026
fd463b0
fix(cli): improve SQLite introspection for untyped columns and compos…
svetch Feb 6, 2026
3b2e2e3
feat(cli): pull generated/computed columns as Unsupported type
svetch Feb 6, 2026
af89f19
fix(cli): Use parameterized queries for MySQL introspection
svetch Feb 7, 2026
a264722
fix(cli): use nullish coalescing for precision check
svetch Feb 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"dependencies": {
"@zenstackhq/common-helpers": "workspace:*",
"@zenstackhq/schema": "workspace:*",
"@zenstackhq/language": "workspace:*",
"@zenstackhq/orm": "workspace:*",
"@zenstackhq/sdk": "workspace:*",
Expand Down
25 changes: 21 additions & 4 deletions packages/cli/src/actions/action-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loadDocument } from '@zenstackhq/language';
import { isDataSource } from '@zenstackhq/language/ast';
import { type ZModelServices, loadDocument } from '@zenstackhq/language';
import { type Model, isDataSource } from '@zenstackhq/language/ast';
import { PrismaSchemaGenerator } from '@zenstackhq/sdk';
import colors from 'colors';
import fs from 'node:fs';
Expand Down Expand Up @@ -41,8 +41,22 @@ export function getSchemaFile(file?: string) {
}
}

export async function loadSchemaDocument(schemaFile: string) {
const loadResult = await loadDocument(schemaFile);
export async function loadSchemaDocument(
schemaFile: string,
opts?: { mergeImports?: boolean; returnServices?: false },
): Promise<Model>;
export async function loadSchemaDocument(
schemaFile: string,
opts: { returnServices: true; mergeImports?: boolean },
): Promise<{ model: Model; services: ZModelServices }>;
export async function loadSchemaDocument(
schemaFile: string,
opts: { returnServices?: boolean; mergeImports?: boolean } = {},
) {
const returnServices = opts.returnServices ?? false;
const mergeImports = opts.mergeImports ?? true;

const loadResult = await loadDocument(schemaFile, [], mergeImports);
if (!loadResult.success) {
loadResult.errors.forEach((err) => {
console.error(colors.red(err));
Expand All @@ -52,6 +66,9 @@ export async function loadSchemaDocument(schemaFile: string) {
loadResult.warnings.forEach((warn) => {
console.warn(colors.yellow(warn));
});

if (returnServices) return { model: loadResult.model, services: loadResult.services };

return loadResult.model;
}

Expand Down
628 changes: 624 additions & 4 deletions packages/cli/src/actions/db.ts

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions packages/cli/src/actions/pull/casing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export function resolveNameCasing(casing: 'pascal' | 'camel' | 'snake' | 'none', originalName: string) {
let name = originalName;
const fieldPrefix = /[0-9]/g.test(name.charAt(0)) ? '_' : '';

switch (casing) {
case 'pascal':
name = toPascalCase(originalName);
break;
case 'camel':
name = toCamelCase(originalName);
break;
case 'snake':
name = toSnakeCase(originalName);
break;
}

return {
modified: name !== originalName || fieldPrefix !== '',
name: `${fieldPrefix}${name}`,
};
}

function isAllUpperCase(str: string): boolean {
return str === str.toUpperCase();
}

export function toPascalCase(str: string): string {
if (isAllUpperCase(str)) return str;
return str.replace(/[_\- ]+(\w)/g, (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c.toUpperCase());
}

export function toCamelCase(str: string): string {
if (isAllUpperCase(str)) return str;
return str.replace(/[_\- ]+(\w)/g, (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c.toLowerCase());
}

export function toSnakeCase(str: string): string {
if (isAllUpperCase(str)) return str;
return str
.replace(/[- ]+/g, '_')
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
.toLowerCase();
}
Loading
Loading