holistics / dbml

Database Markup Language (DBML), designed to define and document database structures
https://dbml.org
Apache License 2.0
2.9k stars 171 forks source link

Postgres: ALTER TABLE test ADD CONSTRAINT not converted to dbml #335

Open nihauc12 opened 1 year ago

nihauc12 commented 1 year ago

Hello 👋 currently trying to import a postgres sql script created by a pg_dump to dbml and it seems to not take into account the unique/primary key constraint.

version 2.5.0 of dbml/core

Minimal script to reproduce:

import fs from 'fs';
import { importer } from '@dbml/core';

const sqlFile = fs.readFileSync(`${__dirname}/test.sql`, 'utf-8');
const dbml = importer.import(sqlFile, 'postgres');
console.log(dbml)

with test.sql being

CREATE TABLE test (
    id integer NOT NULL,
    location character varying(255) NOT NULL
);
ALTER TABLE test ADD CONSTRAINT test_location_key UNIQUE (location);
ALTER TABLE test ADD CONSTRAINT test_pkey PRIMARY KEY (id);

And the result log being

Table "test" {
  "id" integer [not null]
  "location" "character varying(255)" [not null]
}

No pk or unique key.

nguyenalter commented 1 year ago

Hi @nihauc12, currently, our PostgreSQL parser doesn't support altering tables to add unique/primary key constraints. We will let you know as soon as we implement it.