Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Prune non-idempotent objects from pgx-generated SQL #69

Merged
merged 1 commit into from
Feb 10, 2022

Conversation

bitwalker
Copy link
Contributor

@bitwalker bitwalker commented Jan 27, 2022

I've reworked this PR from the ground up. It now depends on changes to pgx, which you can review here.

The changes here take advantage of the new #[to_sql] attribute I introduced, which provides us two options for customizing the SQL generator for specific entities:

  1. We can disable SQL generation entirely for an entity, which I've done in this PR to the GapfillDeltaTransition type
  2. We can handle generating the SQL ourselves, or redirect the generated SQL to an alternative output file. This is not demonstrated in this PR, though I've tested it; but we may want to consider that approach as a means for generating upgrades (there are a number of possibilities here, but the simplest would be generating a separate file for each non-idempotent entity, so that we can easily use those to check our handwritten SQL as well as write new migrations when things change).

As an unrelated aside: I noticed we have some extension_sql! calls still hanging around that do CREATE OPERATOR, we should remember to extract those to migrations.

@bitwalker bitwalker self-assigned this Jan 27, 2022
@JamesGuthrie JamesGuthrie force-pushed the jg/sql-migration-wrapper branch 2 times, most recently from 8fe2a1d to 3e1a8e7 Compare January 27, 2022 10:11
@bitwalker bitwalker force-pushed the bitwalker/pgx-prune branch 2 times, most recently from a909142 to e2fa944 Compare January 28, 2022 01:39
@JamesGuthrie
Copy link
Member

I like how concise this is with #[to_sql(false)]

@bitwalker bitwalker force-pushed the bitwalker/pgx-prune branch from e2fa944 to bd5afc9 Compare January 28, 2022 22:10
@JamesGuthrie JamesGuthrie force-pushed the jg/sql-migration-wrapper branch from 3e1a8e7 to 40c37ce Compare January 31, 2022 13:40
@bitwalker bitwalker force-pushed the bitwalker/pgx-prune branch from bd5afc9 to 304663b Compare February 5, 2022 00:16
@bitwalker bitwalker marked this pull request as ready for review February 5, 2022 00:22
@bitwalker bitwalker changed the title WIP: Prune non-idempotent objects from pgx-generated SQL Prune non-idempotent objects from pgx-generated SQL Feb 5, 2022
Copy link
Contributor

@cevian cevian left a comment

Choose a reason for hiding this comment

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

LGTM

@JamesGuthrie JamesGuthrie changed the base branch from jg/sql-migration-wrapper to develop February 10, 2022 11:28
@JamesGuthrie JamesGuthrie merged commit 7f07272 into develop Feb 10, 2022
@JamesGuthrie JamesGuthrie deleted the bitwalker/pgx-prune branch February 10, 2022 11:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants