sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Add support for ignoring DDL statements using `-- sqlc:ignore`.

Open sgielen opened this issue 1 year ago • 6 comments

NOTE: This PR is in a draft state, because it still requires (at the very least) documentation updates.

This PR adds support for commenting out parts of the schema. This is most useful in the case where the schema is defined by migrations, and such migrations contain queries that are not yet supported by sqlc. See for example #3129, #1756.

By wrapping such unsupported queries in sqlc:ignore comments, they are ignored and the rest of the schema can be parsed appropriately.

Example usage in a migration file:

CREATE TABLE person_email (
  email TEXT NOT NULL
);

-- sqlc:ignore until https://github.com/sqlc-dev/sqlc/issues/3129 is resolved
INSERT INTO person_email (`email`)
  SELECT pe.email
  FROM person AS p
  JOIN JSON_TABLE(p.emails, '$[*]' COLUMNS(email TEXT PATH '$')) AS pe;
-- sqlc:ignore end

ALTER TABLE person_email ADD PRIMARY KEY (`email`);

See https://github.com/sqlc-dev/sqlc/issues/3129 for a full use-case.

Since the lines are actually cleared, instead of removed, errors on queries below the sqlc:ignore end marker are still shown with the correct line number.

sgielen avatar Jan 12 '24 15:01 sgielen

@kyleconroy if you agree with this addition, then I would propose to add some documentation regarding this in https://docs.sqlc.dev/en/stable/howto/ddl.html. I can do that too within this PR, but wanted to await your thoughts first.

sgielen avatar Jan 12 '24 15:01 sgielen

@kyleconroy what do you think about this addition?

sgielen avatar Feb 27 '24 13:02 sgielen

@kyleconroy another bump - marking as non-draft in case that helps

sgielen avatar Apr 14 '24 15:04 sgielen

Hi, @kyleconroy , @sgielen !

Thank you for the feature introduced! I need the same functionality. How can I help with development? For example, with tests?

lisitsky avatar Jun 21 '24 14:06 lisitsky

Hi, @kyleconroy , @sgielen !

Thank you for the feature introduced! I need the same functionality. How can I help with development? For example, with tests?

Hi! @sgielen I've updated the branch, added tests and rebased onto fresh master (it was relatively old), squashed into 1 commit. Could you please have a look? If you find tests useful, feel free to use them in your PR. https://github.com/sqlc-dev/sqlc/pull/3458

lisitsky avatar Jun 25 '24 08:06 lisitsky

Hi, @kyleconroy , @sgielen ! Thank you for the feature introduced! I need the same functionality. How can I help with development? For example, with tests?

Hi! @sgielen I've updated the branch, added tests and rebased onto fresh master (it was relatively old), squashed into 1 commit. Could you please have a look? If you find tests useful, feel free to use them in your PR. #3458

Excellent! Thank you for this. I never wrote additional tests or documentation, because I wanted to hear from the maintainers first, but they never responded to my pings (@kyleconroy trying again). I can close this PR in favor of yours? For context, perhaps your PR's description could link to this one and/or the issues mentioned in my description above?

sgielen avatar Jun 25 '24 13:06 sgielen