Skip to content

Commit

Permalink
CLI: Add --postgres-legacy to import postgres with old parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
NQPhuc committed Aug 24, 2023
1 parent 1e576b2 commit c6667b0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/dbml-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function sql2dbml (args) {
.usage('[options] <files...>')
.option('--mysql')
.option('--postgres')
.option('--postgres-legacy')
.option('--mssql')
.option('-o, --out-file <pathspec>', 'compile all input files into a single files');
// .option('-d, --out-dir <pathspec>', 'compile an input directory of sql files into an output directory');
Expand Down
2 changes: 1 addition & 1 deletion packages/dbml-cli/src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function validateInputFilePaths (paths, validatePlugin) {

function getFormatOpt (opts) {
const formatOpts = Object.keys(opts).filter((opt) => {
return opt === 'postgres' || opt === 'mysql' || opt === 'mssql';
return ['postgres', 'mysql', 'mssql', 'postgresLegacy'].includes(opt);
});

let format = 'postgres';
Expand Down
2 changes: 1 addition & 1 deletion packages/dbml-core/__tests__/parser/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('@dbml/core', () => {
});

test.each(scanTestNames(__dirname, 'postgres-parse/input'))('postgres-parse/%s', (name) => {
runTest(name, 'postgres-parse', 'postgres', 'parsePostgresToJSON');
runTest(name, 'postgres-parse', 'postgres', 'parsePostgresToJSONv2');
});

test.each(scanTestNames(__dirname, 'schemarb-parse/input'))('schemarb-parse/%s', (name) => {
Expand Down
11 changes: 10 additions & 1 deletion packages/dbml-core/src/parse/Parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Database from '../model_structure/database';
import mysqlParser from './mysqlParser';
import postgresParser from './postgresParser';
import dbmlParser from './dbmlParser';
import schemarbParser from './schemarbParser';
import mssqlParser from './mssqlParser';
Expand All @@ -15,10 +16,14 @@ class Parser {
return mysqlParser.parse(str);
}

static parsePostgresToJSON (str) {
static parsePostgresToJSONv2 (str) {
return parse(str, 'postgres');
}

static parsePostgresToJSON (str) {
return postgresParser.parse(str);
}

static parseDBMLToJSON (str) {
return dbmlParser.parse(str);
}
Expand All @@ -39,6 +44,10 @@ class Parser {
break;

case 'postgres':
rawDatabase = Parser.parsePostgresToJSONv2(str);
break;

case 'postgresLegacy':
rawDatabase = Parser.parsePostgresToJSON(str);
break;

Expand Down
2 changes: 1 addition & 1 deletion packages/dbml-core/types/import/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare function _import(str: string, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql'): string;
declare function _import(str: string, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'postgresLegacy'): string;
declare const _default: {
import: typeof _import;
};
Expand Down
1 change: 1 addition & 0 deletions packages/dbml-core/types/parse/Parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ declare class Parser {
static parseJSONToDatabase(rawDatabase: RawDatabase): Database;
static parseMySQLToJSON(str: string): RawDatabase;
static parsePostgresToJSON(str: string): RawDatabase;
static parsePostgresToJSONv2(str: string): RawDatabase;
static parseDBMLToJSON(str: string): RawDatabase;
static parseSchemaRbToJSON(str: string): RawDatabase;
static parseMSSQLToJSON(str: string): RawDatabase;
Expand Down

0 comments on commit c6667b0

Please sign in to comment.