-
Notifications
You must be signed in to change notification settings - Fork 194
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
Add Ord instance on schema, enables sorted table names in IDE #584
base: master
Are you sure you want to change the base?
Add Ord instance on schema, enables sorted table names in IDE #584
Conversation
When reordering the full Schema.sql we'll have edge cases that causes errors, e.g. a enum type always has to be declared before it can be used inside a table DDL statement. The user could also be using a text editor to edit the Schema.sql and then the reorder could be a bit annoying. But maybe we could sort the tables inside the render function of the table list of the GUI? |
I wondered if that might be the case; I am happy to change it. An other option is to write the Ord instance to order statements in a manner that is appropriate for the order of the SQL declarations, which might avoid other statement ordering issues in the future? (I have noticed that the generation of the foreign key constraints appears to not be deterministic; I believe the order of the type parameters can change depending on the order of the constraint statements). |
Very good point 👍 Let's give this a try with custom Ord instances. Order should be defined like this: CREATE EXTENSION
CREATE TYPE
CREATE TABLE
ALTER TABLE .. -- FKs Then there's still an open edge case: When the CREATE TABLE projects (
id UUID,
user_id UUID,
PRIMARY KEY (id),
CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users
) Then this table needs to be placed after the To avoid this issue the schema designer always uses |
f59ff58
to
1dcc70d
Compare
I've added the Ord instance for Statement, but this change still does not address (a) the situation of a user editing the schema manually and having schema order change underneath them, and (b) any inline foreign key constraints needing to be sorted after the table definition. Perhaps (b) could have an Ord instance of CreateTable to sort any in-line constraint tables to appear last? The IDE display of table names would be quirky under this scenario. |
How do we feel about this?