Skip to content
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 support for ?dialect=postgresql to /api/migrations #956

Closed
wants to merge 3 commits into from

Conversation

alco
Copy link
Member

@alco alco commented Feb 15, 2024

Closes VAX-1659.

Passing ?dialect=postgresql to /api/migrations will now result in the returned migrations to have the original Postgres DDL.

Copy link

linear bot commented Feb 15, 2024

@alco alco changed the title Add support for ?dialect=postgresl to /api/migrations Add support for ?dialect=postgresql to /api/migrations Feb 15, 2024
@alco alco force-pushed the alco/vax-1659-postgresql-dialect branch 2 times, most recently from 5d932fd to f573c5f Compare February 15, 2024 12:12
Copy link
Contributor

@magnetised magnetised left a comment

Choose a reason for hiding this comment

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

I think this is exactly the way to do it. maybe we should sort out that type field in the migration message now though. what is it for? i'm guessing the intention was to make the schema info available to the clients without them having to parse the migration sql, In which case what's the best way to pass that? we could have a generic structure that gave the base type as a string and any modifiers (like length, precision etc) as a map or something? if we knew we were only ever going to support sqlite and pg, then what we have works but that makes me wary.

}
end

defp replication_msg_table_col(%Proto.Column{} = column, dialect) do
defp replication_msg_table_col(%Proto.Column{} = column) do
%SatOpMigrate.Column{
name: column.name,
pg_type: replication_msg_table_col_type(column.type),
Copy link
Contributor

Choose a reason for hiding this comment

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

my original {sqlite,pg}_type thing makes no sense. why don't we just have type here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe I left both sqlite_type and pg_type here to avoid breaking existing code, as this was a POC. I did mark both as deprecated in the protocol definition, so ideally only type_info should remain.

But as of #1054, Kevin and I encountered some TypeScript typing issues with type_info. Long story short, the latest iteration of this changes now lives in #1065 where sqlite_type is deprecated (can be removed today, just needs some client-side tests for /api/migrations updated) and only pg_type remain as the source of truth for the column type.

columns: [
%SatOpMigrate.Column{
name: "id",
sqlite_type: "TEXT",
Copy link
Contributor

Choose a reason for hiding this comment

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

so the pg_type bit carries the original type info dropped by the conversion to sqlite's type. hmm. perhaps just dropping the sqlite_ prefix and having a dialect-defined type which is just a string?

@alco
Copy link
Member Author

alco commented Feb 19, 2024

@magnetised

we could have a generic structure that gave the base type as a string and any modifiers (like length, precision etc) as a map or something?

We have the PgColumnType message that can be extended with more info over time.

From looking at the client code, it doesn't need sqlite_type and can only use pg_type to determine correct value encoding/decoding based on the original PG schema.

So we can drop sqlite_type, rename pg_type to type_info or just type and populate it with PG type info regardless of the chosen dialect.

@alco alco force-pushed the alco/vax-1659-postgresql-dialect branch from f2579d6 to 12e769b Compare March 14, 2024 08:28
@alco alco closed this Mar 15, 2024
@alco alco deleted the alco/vax-1659-postgresql-dialect branch April 18, 2024 20:51
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.

None yet

2 participants