Skip to content

feat: add support for PostgreSQL table inheritance in schema export #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kishansinghifs1
Copy link
Contributor

Summary

This PR adds full support for PostgreSQL table inheritance in the schema export generator (#472).


What's Included

  • ✅ Proper generation of INHERITS clause in CREATE TABLE statements.
  • ✅ Child tables only include non-inherited fields in SQL output.
  • ✅ Parent table fields are automatically inherited by child tables.
  • ✅ Maintains correct handling of:
    • PRIMARY KEY, UNIQUE, NOT NULL
    • DEFAULT, CHECK, and ARRAY modifiers.
  • ✅ Table and column comments are still supported.

Implementation Notes

  • Used table.inherits array to determine parent table(s).
  • Computed inheritedFieldNames from parent tables to avoid duplication.
  • Adjusted PRIMARY KEY generation to apply only to non-inherited fields in child tables.

🖥️ Screen Recording

![Watch demo](

freecompress-Recording.2025-06-14.112023.mp4

)

Copy link

vercel bot commented Jun 14, 2025

Someone is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Jun 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
drawdb ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 14, 2025 9:56am

Copy link
Member

@1ilit 1ilit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to work on this

<div className="min-w-20 flex-1/3">
<div
className="min-w-20 flex-1/3"
style={inherited ? { opacity: 0.6 } : {}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
style={inherited ? { opacity: 0.6 } : {}}

<Input
value={data.name}
id={`scroll_table_${tid}_input_${index}`}
validateStatus={data.name.trim() === "" ? "error" : "default"}
validateStatus={
data.name.trim() === "" && !inherited ? "error" : "default"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

names still shouldnt be empty and overriding an inherited fields should result in an error

Suggested change
data.name.trim() === "" && !inherited ? "error" : "default"
data.name.trim() === "" || inherited ? "error" : "default"

@@ -49,7 +54,12 @@ export default function TableField({ data, tid, index }) {
]);
setRedoStack([]);
}}
readOnly={inherited}
style={inherited ? { backgroundColor: "#f5f5f5" } : {}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

causes
image

Suggested change
style={inherited ? { backgroundColor: "#f5f5f5" } : {}}

/>
{inherited && (
<span style={{ fontSize: 12, color: "#888" }}>Inherited</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when an inherited field gets overridden an error should be reported, instead of showing this here please add an issue in issues.js


return (
<div>
{database === DB.POSTGRES && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this below the tablefield list above comments

the table info should start with the most characteristic attributes such as name and columns

.map((t) => ({ label: t.name, value: t.name }))}
onChange={(value) => updateTable(data.id, { inherits: value })}
placeholder="Select parent tables"
style={{ width: "100%" }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tailwind please

@@ -56,6 +56,10 @@ export const tableSchema = {
},
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
},
inherits: {
type: "array",
items: { type: ["string", "integer"] },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can it be an integer?

Suggested change
items: { type: ["string", "integer"] },
items: { type: ["string"] },


return (
<div>
{database === DB.POSTGRES && (
<div className="mb-2">
<div className="text-md font-semibold break-keep">Inherits:</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use translation please

Suggested change
<div className="text-md font-semibold break-keep">Inherits:</div>
<div className="text-md font-semibold break-keep">{t('inherits')}:</div>

)
.join("\n");

return `CREATE TABLE "${table.name}" (\n${fieldDefinitions}${primaryKeyClause}${inheritsClause};\n${commentStatements}\n${indexStatements}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

please have the closing parenthesis be on a new line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants