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 ignoring DDL statements using -- sqlc:ignore. #3130

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sgielen
Copy link

@sgielen sgielen commented Jan 12, 2024

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 #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 sgielen changed the title Add support for ignoring DDL statements using // sqlc:ignore. Add support for ignoring DDL statements using -- sqlc:ignore. Jan 12, 2024
@sgielen
Copy link
Author

sgielen commented Jan 12, 2024

@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
Copy link
Author

sgielen commented Feb 27, 2024

@kyleconroy what do you think about this addition?

@sgielen sgielen marked this pull request as ready for review April 14, 2024 15:29
@sgielen
Copy link
Author

sgielen commented Apr 14, 2024

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

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

1 participant