-
Notifications
You must be signed in to change notification settings - Fork 103
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
✨ feat: enhance schema to adopt constraints
data
#1168
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: f2f2abe The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@tnyo43 is attempting to deploy a commit to the ROUTE06 Core Team on Vercel. A member of the Team first needs to authorize it. |
@@ -95,6 +95,7 @@ async function parsePrismaSchema(schemaString: string): Promise<ProcessResult> { | |||
columns, | |||
comment: model.documentation ?? null, | |||
indices: {}, | |||
constraints: {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR won't update the other format parsers other than tbls because I think it will make this change too large.
const cardinalitySchema = v.picklist(['ONE_TO_ONE', 'ONE_TO_MANY']) | ||
export type Cardinality = v.InferOutput<typeof cardinalitySchema> | ||
|
||
const foreignKeyConstraintSchema = v.picklist([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the new constraint schemas will be named as foreignKeyConstraintSchema
, so it will rename this schema as foreignKeyConstraintReferenceOptionSchema
(it's a little bit hard to find the diffs because this PR will change the order of declarations 😓 )
I refer to the MySQL document to to name the schema as ReferenceOption
. https://dev.mysql.com/doc/refman/8.4/en/create-table-foreign-keys.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏻
const primaryKeyConstraintSchema = v.object({ | ||
type: v.literal('PRIMARY KEY'), | ||
name: constraintNameSchema, | ||
columnNames: v.array(columnNameSchema), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might not be considering adopting a composite key. If not, I'm planning to modify it like the follows and fix the related codes:
columnNames: v.array(columnNameSchema), | |
columnName: columnNameSchema, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to support composite keys because we want to accurately represent the state of our database.
However, I also feel that this is a feature that is not used very often. Please let me know if support would greatly complicate the implementation and experience.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
This comment was marked as resolved.
This comment was marked as resolved.
the current `foreignKeyConstraintSchema` does not represents foreign key constraint itself but its reference option. I refer to the MySQL document to to name the schema as `ReferenceOption` ref: https://dev.mysql.com/doc/refman/8.4/en/create-table-foreign-keys.html
8acfdbe
to
f67e2df
Compare
* 1. Apply overrides to existing tables (e.g., replacing comments) | ||
* 2. Add new columns to existing tables | ||
* 3. Add new relationships | ||
* 4. Process and merge table groups from both original structure and overrides | ||
* 1. Apply overrides to existing tables | ||
* 1.1. Replace comments | ||
* 1.2. Add new columns | ||
* 1.3. Add new constraints | ||
* 2. Add new relationships | ||
* 3. Process and merge table groups from both original structure and overrides |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I arranged it a little because I think "adding new columns" step is a part of "applying overrides to existing tables". Does that align with your intention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, we now have a policy of not unnecessarily adding more information to overrideDbStructure. Can you turn it off now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!! almost good, please check comments!
const cardinalitySchema = v.picklist(['ONE_TO_ONE', 'ONE_TO_MANY']) | ||
export type Cardinality = v.InferOutput<typeof cardinalitySchema> | ||
|
||
const foreignKeyConstraintSchema = v.picklist([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏻
const primaryKeyConstraintSchema = v.object({ | ||
type: v.literal('PRIMARY KEY'), | ||
name: constraintNameSchema, | ||
columnNames: v.array(columnNameSchema), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to support composite keys because we want to accurately represent the state of our database.
However, I also feel that this is a feature that is not used very often. Please let me know if support would greatly complicate the implementation and experience.
* 1. Apply overrides to existing tables (e.g., replacing comments) | ||
* 2. Add new columns to existing tables | ||
* 3. Add new relationships | ||
* 4. Process and merge table groups from both original structure and overrides | ||
* 1. Apply overrides to existing tables | ||
* 1.1. Replace comments | ||
* 1.2. Add new columns | ||
* 1.3. Add new constraints | ||
* 2. Add new relationships | ||
* 3. Process and merge table groups from both original structure and overrides |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, we now have a policy of not unnecessarily adding more information to overrideDbStructure. Can you turn it off now?
Issue
constraints
data, such as primary key, unique, foreign key and check constraitns.Why is this change needed?
The current db-structure schema drops the
constraints
data of tbls schema. Especially, check constraints of the schema can't be expressed with the current schema.This PR will enhance the schema to adopt
constraints
data and prepare for implementing the UI using it.What would you like reviewers to focus on?
tbls
format parser with constraintsTesting Verification
What was done
🤖 Generated by PR Agent at 8acfdbe
PRIMARY KEY
,FOREIGN KEY
,UNIQUE
, andCHECK
constraints.PRIMARY KEY
,FOREIGN KEY
,UNIQUE
, andCHECK
constraints.Detailed Changes
8 files
Add constraints handling to Prisma schema parser
Add constraints handling to Schema.rb parser
Add constraints handling to PostgreSQL schema converter
Add constraints handling to tbls schema parser
Define schema for constraints and integrate into table schema
Update table factory to include constraints
Export constraints-related types and schemas
Add support for overriding constraints in database structure
2 files
Add tests for constraints in tbls schema parser
Add tests for overriding constraints in database structure
1 files
Add changeset for constraints enhancement
Additional Notes