dbml icon indicating copy to clipboard operation
dbml copied to clipboard

Postgres: ALTER TABLE test ADD CONSTRAINT not converted to dbml

Open nihauc12 opened this issue 2 years ago • 1 comments
trafficstars

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.

nihauc12 avatar Feb 15 '23 22:02 nihauc12

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.

nguyenalter avatar Feb 16 '23 05:02 nguyenalter