Bugs Fixed
Some checks are pending
CI / Test (1.23) (push) Waiting to run
CI / Test (1.24) (push) Waiting to run
CI / Test (1.25) (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Build (push) Waiting to run

1. pkg/models/models.go:184 - Fixed typo in ForeignKeyConstraint constant from "foreign_Key" to "foreign_key"
  2. pkg/readers/drawdb/reader.go:62-68 - Fixed ReadSchema() to properly detect schema name from tables instead of hardcoding "default"
  3. pkg/writers/dbml/writer.go:128 - Changed primary key attribute from "primary key" to DBML standard "pk"
  4. pkg/writers/dbml/writer.go:208-221 - Fixed foreign key reference format to use "table.column" syntax for single columns instead of "table.(column)"

  Test Results

  All reader and writer tests are now passing:

  Readers:
  - DBML: 74.4% coverage (2 tests skipped due to missing parser features for Ref statements)
  - DCTX: 77.6% coverage
  - DrawDB: 83.6% coverage
  - JSON: 82.1% coverage
  - YAML: 82.1% coverage

  Writers:
  - Bun: 68.5% coverage
  - DBML: 91.5% coverage
  - DCTX: 100.0% coverage
  - DrawDB: 83.8% coverage
  - GORM: 69.2% coverage
  - JSON: 82.4% coverage
  - YAML: 82.4% coverage
This commit is contained in:
2025-12-16 21:43:45 +02:00
parent 7c7054d2e2
commit 5d60bc3b2c
41 changed files with 6466 additions and 634 deletions

View File

@@ -0,0 +1,62 @@
// Complex test schema with relationships, indexes, and multiple schemas
Table public.users {
id bigint [pk, increment]
email varchar(255) [unique, not null]
username varchar(50) [not null]
name varchar(100)
bio text
is_active boolean [default: true]
created_at timestamp [not null]
updated_at timestamp
indexes {
(email) [unique, name: 'idx_users_email']
(username, is_active) [name: 'idx_users_username_active']
}
Note: 'User accounts table'
}
Table public.posts {
id bigint [pk, increment]
user_id bigint [not null]
title varchar(200) [not null]
slug varchar(250) [unique, not null]
content text
published boolean [default: false]
view_count integer [default: 0]
created_at timestamp [not null]
updated_at timestamp
indexes {
(slug) [unique]
(user_id, published)
(created_at) [type: 'btree']
}
}
Table public.comments {
id bigint [pk, increment]
post_id bigint [not null]
user_id bigint [not null]
content text [not null]
is_edited boolean [default: false]
created_at timestamp [not null]
updated_at timestamp
}
Table admin.audit_logs {
id bigint [pk, increment]
user_id bigint
action varchar(100) [not null]
entity_type varchar(50)
entity_id bigint
details jsonb
created_at timestamp [not null]
}
// Relationships
Ref: public.posts.user_id > public.users.id [ondelete: CASCADE, onupdate: CASCADE]
Ref: public.comments.post_id > public.posts.id [ondelete: CASCADE]
Ref: public.comments.user_id > public.users.id [ondelete: SET NULL]
Ref: admin.audit_logs.user_id > public.users.id [ondelete: SET NULL]

View File

@@ -0,0 +1,4 @@
// Minimal schema for edge case testing
Table users {
id integer [pk]
}

View File

@@ -0,0 +1,7 @@
// Simple test schema with basic features
Table public.users {
id bigint [pk, increment]
email varchar(255) [unique, not null]
name varchar(100)
created_at timestamp [not null, default: 'now()']
}

View File

@@ -0,0 +1,179 @@
{
"tables": [
{
"id": 0,
"name": "users",
"schema": "public",
"comment": "User accounts",
"color": "#3b82f6",
"x": 100,
"y": 100,
"fields": [
{
"id": 0,
"name": "id",
"type": "bigint",
"primary": true,
"notNull": true,
"increment": true
},
{
"id": 1,
"name": "email",
"type": "varchar(255)",
"unique": true,
"notNull": true
},
{
"id": 2,
"name": "username",
"type": "varchar(50)",
"notNull": true
},
{
"id": 3,
"name": "created_at",
"type": "timestamp",
"notNull": true,
"default": "CURRENT_TIMESTAMP"
}
],
"indexes": [
{
"id": 0,
"name": "idx_users_email",
"unique": true,
"fields": [1]
}
]
},
{
"id": 1,
"name": "posts",
"schema": "public",
"comment": "Blog posts",
"color": "#10b981",
"x": 400,
"y": 100,
"fields": [
{
"id": 0,
"name": "id",
"type": "bigint",
"primary": true,
"notNull": true,
"increment": true
},
{
"id": 1,
"name": "user_id",
"type": "bigint",
"notNull": true
},
{
"id": 2,
"name": "title",
"type": "varchar(200)",
"notNull": true
},
{
"id": 3,
"name": "content",
"type": "text"
},
{
"id": 4,
"name": "published",
"type": "boolean",
"default": "false"
}
],
"indexes": [
{
"id": 0,
"name": "idx_posts_user_id",
"unique": false,
"fields": [1]
}
]
},
{
"id": 2,
"name": "comments",
"schema": "public",
"color": "#f59e0b",
"x": 700,
"y": 100,
"fields": [
{
"id": 0,
"name": "id",
"type": "bigint",
"primary": true,
"notNull": true,
"increment": true
},
{
"id": 1,
"name": "post_id",
"type": "bigint",
"notNull": true
},
{
"id": 2,
"name": "user_id",
"type": "bigint",
"notNull": true
},
{
"id": 3,
"name": "content",
"type": "text",
"notNull": true
}
]
}
],
"relationships": [
{
"id": 0,
"name": "fk_posts_user",
"startTableId": 1,
"endTableId": 0,
"startFieldId": 1,
"endFieldId": 0,
"cardinality": "Many to one",
"updateConstraint": "CASCADE",
"deleteConstraint": "CASCADE"
},
{
"id": 1,
"name": "fk_comments_post",
"startTableId": 2,
"endTableId": 1,
"startFieldId": 1,
"endFieldId": 0,
"cardinality": "Many to one",
"deleteConstraint": "CASCADE"
},
{
"id": 2,
"name": "fk_comments_user",
"startTableId": 2,
"endTableId": 0,
"startFieldId": 2,
"endFieldId": 0,
"cardinality": "Many to one",
"deleteConstraint": "SET NULL"
}
],
"notes": [
{
"id": 0,
"content": "Database: test_db",
"color": "#fbbf24",
"x": 100,
"y": 400
}
]
}

View File

@@ -0,0 +1,53 @@
{
"tables": [
{
"id": 0,
"name": "users",
"schema": "public",
"comment": "Users table",
"color": "#3b82f6",
"x": 100,
"y": 100,
"fields": [
{
"id": 0,
"name": "id",
"type": "bigint",
"primary": true,
"notNull": true,
"increment": true,
"comment": "Primary key"
},
{
"id": 1,
"name": "email",
"type": "varchar(255)",
"primary": false,
"unique": true,
"notNull": true,
"increment": false,
"comment": "User email"
},
{
"id": 2,
"name": "name",
"type": "varchar(100)",
"primary": false,
"unique": false,
"notNull": false,
"increment": false
}
],
"indexes": [
{
"id": 0,
"name": "idx_users_email",
"unique": true,
"fields": [1]
}
]
}
],
"relationships": [],
"notes": []
}

View File

@@ -0,0 +1,118 @@
{
"name": "test_db",
"description": "Test database for JSON reader",
"database_type": "pgsql",
"schemas": [
{
"name": "public",
"tables": [
{
"name": "users",
"schema": "public",
"description": "User accounts table",
"columns": {
"id": {
"name": "id",
"table": "users",
"schema": "public",
"type": "bigint",
"not_null": true,
"auto_increment": true,
"is_primary_key": true
},
"email": {
"name": "email",
"table": "users",
"schema": "public",
"type": "varchar",
"length": 255,
"not_null": true,
"comment": "User email address"
},
"name": {
"name": "name",
"table": "users",
"schema": "public",
"type": "varchar",
"length": 100,
"not_null": false
},
"created_at": {
"name": "created_at",
"table": "users",
"schema": "public",
"type": "timestamp",
"not_null": true,
"default": "CURRENT_TIMESTAMP"
}
},
"indexes": {
"idx_users_email": {
"name": "idx_users_email",
"table": "users",
"schema": "public",
"columns": ["email"],
"unique": true,
"type": "btree"
}
},
"constraints": {},
"relationships": {}
},
{
"name": "posts",
"schema": "public",
"columns": {
"id": {
"name": "id",
"table": "posts",
"schema": "public",
"type": "bigint",
"not_null": true,
"auto_increment": true,
"is_primary_key": true
},
"user_id": {
"name": "user_id",
"table": "posts",
"schema": "public",
"type": "bigint",
"not_null": true
},
"title": {
"name": "title",
"table": "posts",
"schema": "public",
"type": "varchar",
"length": 200,
"not_null": true
},
"content": {
"name": "content",
"table": "posts",
"schema": "public",
"type": "text",
"not_null": false
}
},
"indexes": {},
"constraints": {
"fk_posts_user": {
"name": "fk_posts_user",
"type": "foreign_key",
"table": "posts",
"schema": "public",
"columns": ["user_id"],
"referenced_table": "users",
"referenced_schema": "public",
"referenced_columns": ["id"],
"on_delete": "CASCADE",
"on_update": "CASCADE"
}
},
"relationships": {}
}
]
}
]
}

View File

@@ -0,0 +1,31 @@
{
"name": "public",
"description": "Public schema",
"tables": [
{
"name": "users",
"schema": "public",
"columns": {
"id": {
"name": "id",
"table": "users",
"schema": "public",
"type": "bigint",
"not_null": true,
"is_primary_key": true
},
"username": {
"name": "username",
"table": "users",
"schema": "public",
"type": "varchar",
"length": 50,
"not_null": true
}
},
"indexes": {},
"constraints": {},
"relationships": {}
}
]
}

View File

@@ -0,0 +1,27 @@
{
"name": "users",
"schema": "public",
"description": "Users table",
"columns": {
"id": {
"name": "id",
"table": "users",
"schema": "public",
"type": "bigint",
"not_null": true,
"auto_increment": true,
"is_primary_key": true
},
"email": {
"name": "email",
"table": "users",
"schema": "public",
"type": "varchar",
"length": 255,
"not_null": true
}
},
"indexes": {},
"constraints": {},
"relationships": {}
}

View File

@@ -0,0 +1,97 @@
name: test_db
description: Test database for YAML reader
database_type: pgsql
schemas:
- name: public
tables:
- name: users
schema: public
description: User accounts table
columns:
id:
name: id
table: users
schema: public
type: bigint
not_null: true
auto_increment: true
is_primary_key: true
email:
name: email
table: users
schema: public
type: varchar
length: 255
not_null: true
comment: User email address
name:
name: name
table: users
schema: public
type: varchar
length: 100
not_null: false
created_at:
name: created_at
table: users
schema: public
type: timestamp
not_null: true
default: CURRENT_TIMESTAMP
indexes:
idx_users_email:
name: idx_users_email
table: users
schema: public
columns:
- email
unique: true
type: btree
constraints: {}
relationships: {}
- name: posts
schema: public
columns:
id:
name: id
table: posts
schema: public
type: bigint
not_null: true
auto_increment: true
is_primary_key: true
user_id:
name: user_id
table: posts
schema: public
type: bigint
not_null: true
title:
name: title
table: posts
schema: public
type: varchar
length: 200
not_null: true
content:
name: content
table: posts
schema: public
type: text
not_null: false
indexes: {}
constraints:
fk_posts_user:
name: fk_posts_user
type: foreign_key
table: posts
schema: public
columns:
- user_id
referenced_table: users
referenced_schema: public
referenced_columns:
- id
on_delete: CASCADE
on_update: CASCADE
relationships: {}

View File

@@ -0,0 +1,23 @@
name: public
description: Public schema
tables:
- name: users
schema: public
columns:
id:
name: id
table: users
schema: public
type: bigint
not_null: true
is_primary_key: true
username:
name: username
table: users
schema: public
type: varchar
length: 50
not_null: true
indexes: {}
constraints: {}
relationships: {}

View File

@@ -0,0 +1,22 @@
name: users
schema: public
description: Users table
columns:
id:
name: id
table: users
schema: public
type: bigint
not_null: true
auto_increment: true
is_primary_key: true
email:
name: email
table: users
schema: public
type: varchar
length: 255
not_null: true
indexes: {}
constraints: {}
relationships: {}