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 a check to find object names that do not follow naming convention #524

Open
mfvanek opened this issue Dec 4, 2024 · 3 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@mfvanek
Copy link
Owner

mfvanek commented Dec 4, 2024

SQL identifiers and key words must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_).

See https://www.postgresql.org/docs/17/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

But using liquibase XML syntax we can easily get wrong names

  <changeSet author="author" id="add-index-on-task-expiration-date-status-v2">
    <createIndex tableName="my_task" indexName="idx-my-task-expired-at-status">
      <column name="task_expired_at"/>
      <column name="task_status"/>
    </createIndex>
  </changeSet>
IndexWithNulls.of("my_task", "\"idx-my-task-expired-at-status\"", 0L, "task_expired_at")
@mfvanek mfvanek added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Dec 4, 2024
@gmottajr
Copy link

gmottajr commented Dec 7, 2024

Hi @mfvanek,
Can I collaborate through this one?

Required Clarifications

Before starting to work on the issue, I have a few questions to ensure alignment:

  1. Scope of Validation:

    • Should this check be limited to Liquibase XML configurations?
    • Or should it be a general utility for validating any SQL object names?
  2. Expected Workflow:

    • Should this validation run as part of build-time checks (e.g., Maven/Gradle plugin)?
    • Should it be integrated into Liquibase migrations to validate during execution?
  3. Handling Violations:

    • How should violations be handled?
      • Errors that fail the build/execution?
      • Warnings that flag potential issues?
      • Automatic fixes (e.g., sanitizing invalid names)?
  4. Integration Point:

    • Should this validation be integrated into an existing framework or tool in your codebase?
    • Or should it be a standalone utility/module?
  5. Test Cases:

    • Can you provide examples of edge cases or problematic names you've encountered? This would help ensure comprehensive testing.
  6. Acceptance Criteria:

    • Can you list some specific acceptance criteria for this feature?

Let me know if there’s anything else you'd like me to consider or if you have preferences for implementation details. Looking forward to your feedback!

@mfvanek
Copy link
Owner Author

mfvanek commented Dec 7, 2024

Hi @gmottajr
Take a look at series of articles

Also please read

and

Sorry, currently only in russian. Please use machine translation.

We use the system catalog (pg_catalog) https://www.postgresql.org/docs/current/catalogs.html and work with finite database state (after all migrations are applied).


Should this check be limited to Liquibase XML configurations?

No, it shouldn't
It should starts as an sql query to find all misspelled names in system catalog.
See https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/possible_object_name_overflow.sql as basic example

@mfvanek
Copy link
Owner Author

mfvanek commented Dec 12, 2024

See also

Linter: schemacrawler.tools.linter.LinterTableWithQuotedNames
Checks for tables that have spaces in table or column names, or names that are reserved words in the ANSI SQL standard.

https://www.schemacrawler.com/lint.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants