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

fix(operators)!: swap operator types #1024

Merged
merged 1 commit into from
Apr 3, 2024
Merged

Conversation

Shinigami92
Copy link
Collaborator

@Shinigami92 Shinigami92 commented Mar 8, 2024

@Shinigami92 Shinigami92 added c: bug Something isn't working p: 3-urgent Fix and release ASAP labels Mar 8, 2024
@Shinigami92 Shinigami92 added this to the v7.0 milestone Mar 8, 2024
@Shinigami92 Shinigami92 self-assigned this Mar 8, 2024
Copy link

github-actions bot commented Mar 8, 2024

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 93.4% (🎯 90%)
⬆️ +1.40%
4404 / 4715
🟢 Statements 93.4% (🎯 90%)
⬆️ +1.40%
4404 / 4715
🟢 Functions 95% (🎯 90%)
⬆️ +2.09%
228 / 240
🟢 Branches 87.38% (🎯 85%)
⬇️ -0.13%
748 / 856
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Unchanged Files
src/db.ts 87.87% 88.46% 87.5% 87.87% 66-68, 97, 100-112, 152-154
src/index.ts 100% 100% 100% 100%
src/migration-builder.ts 97.38% 92.3% 87.5% 97.38% 330-334, 461-466, 490-491
src/migration.ts 78.26% 78.04% 58.33% 78.26% 65, 69, 72-80, 110-112, 117-153, 210-211, 236-239, 247-248, 265-268, 297-298
src/runner.ts 74.43% 58.18% 80% 74.43% 42, 69-70, 79-80, 84-91, 129-130, 169-172, 181-185, 198, 203-215, 234, 236-242, 245, 258, 270-283, 286-289, 299-300, 309-311, 320, 322-331, 343-350
src/sqlMigration.ts 92% 100% 80% 92% 47-50
src/types.ts 100% 100% 100% 100%
src/utils.ts 96.81% 88.63% 100% 96.81% 115, 133, 206-207, 210-211, 218-219
src/operations/PgLiteral.ts 86.66% 100% 50% 86.66% 13-14
src/operations/domains.ts 100% 100% 100% 100%
src/operations/extensions.ts 100% 100% 100% 100%
src/operations/functions.ts 100% 100% 100% 100%
src/operations/indexes.ts 94.15% 91.22% 100% 94.15% 21, 31-34, 43, 72, 121-122
src/operations/operators.ts 98.34% 90.9% 100% 98.34% 147-148, 160-162
src/operations/other.ts 100% 100% 100% 100%
src/operations/policies.ts 100% 94.44% 100% 100%
src/operations/roles.ts 97.2% 77.27% 100% 97.2% 57, 63, 70, 77
src/operations/schemas.ts 100% 100% 100% 100%
src/operations/sequences.ts 92.42% 82.85% 100% 92.42% 32, 34-35, 40-41, 54-55, 60-61, 109
src/operations/tables.ts 89.89% 83.87% 96.66% 89.89% 64-65, 68-69, 120-124, 149, 153-154, 173-174, 199-200, 203-210, 213-214, 353-378, 417-421, 436, 446-447, 552, 561-569
src/operations/triggers.ts 92.66% 78.78% 100% 92.66% 59-60, 72-73, 76-77, 80-83, 124
src/operations/types.ts 100% 100% 100% 100%
src/operations/views.ts 100% 95.55% 100% 100%
src/operations/viewsMaterialized.ts 100% 97.77% 100% 100%
Generated in workflow #241

@Shinigami92 Shinigami92 requested a review from goce-cz March 8, 2024 22:27
@Shinigami92
Copy link
Collaborator Author

@goce-cz or any other person (e.g. @ST-DDT, @dolezel or @littlewhywhat) should have a look if this is a correct fix

@Shinigami92 Shinigami92 force-pushed the fix/swaps-operation-types branch from ac7cfd1 to 584c1d4 Compare March 8, 2024 22:41
Copy link
Contributor

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

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

Do you have integration tests that actually run these commands against a postgres?

Comment on lines +111 to +123
`CREATE OPERATOR CLASS "gist__int_ops" DEFAULT FOR TYPE "_int4" USING "gist" AS
OPERATOR 3 "&&",
OPERATOR 6 "="(anyarray, anyarray),
OPERATOR 7 "@>",
OPERATOR 8 "<@",
OPERATOR 20 "@@"(_int4, query_int),
FUNCTION 1 "g_int_consistent"(internal, _int4, smallint, oid, internal),
FUNCTION 2 "g_int_union"(internal, internal),
FUNCTION 3 "g_int_compress"(internal),
FUNCTION 4 "g_int_decompress"(internal),
FUNCTION 5 "g_int_penalty"(internal, internal, internal),
FUNCTION 6 "g_int_picksplit"(internal, internal),
FUNCTION 7 "g_int_same"(_int4, _int4, internal);`
Copy link
Contributor

Choose a reason for hiding this comment

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

If I throw that against a postgres, I get:

ERROR:  syntax error at or near ","
LINE 2:   OPERATOR 3 "&&",

It get's slightly better, when you remove the quotes:

As shown by the example from postgres:

CREATE OPERATOR CLASS gist__int_ops
    DEFAULT FOR TYPE _int4 USING gist AS
        OPERATOR        3       &&,
        OPERATOR        6       = (anyarray, anyarray),
        OPERATOR        7       @>,
        OPERATOR        8       <@,
        OPERATOR        20      @@ (_int4, query_int),
        FUNCTION        1       g_int_consistent (internal, _int4, smallint, oid, internal),
        FUNCTION        2       g_int_union (internal, internal),
        FUNCTION        3       g_int_compress (internal),
        FUNCTION        4       g_int_decompress (internal),
        FUNCTION        5       g_int_penalty (internal, internal, internal),
        FUNCTION        6       g_int_picksplit (internal, internal),
        FUNCTION        7       g_int_same (_int4, _int4, internal);

Sadly even with that I get an error:

ERROR:  operator does not exist: integer[] && integer[]

But that might be caused by my test setup being cobbled together.
(or me not having a clue, what this does/it is used for)

@Shinigami92
Copy link
Collaborator Author

Do you have integration tests that actually run these commands against a postgres?

I looked into the integration tests and nope, there are no integration tests that calls *OperatorClass at all.

Integration tests are on my mental list and will be improved after I have covered a good minimum with unit tests, because the unit tests are also running on my local setup and not only in CI/CD.


I do not have problems with the quotes yet, because the migration builder is called with options where you can configure the behavior.
So a quick explanation how node-pg-migrate works:
Functions like createOperatorClass will be called from the migration builder passing a migration options object containing e.g. options for how to handle quotation. The migration options do have a literal option where you can configure createSchemalize(_, /* shouldQuote: */ true) to set ".
The current unit tests uses options1 from test/utils.ts and this does have exactly this set.
My current main-goal is to write unit tests that covers the src-code base (and later the bin-code base). I only fix "small" issues like chore: whitespaces or things like these where obviously I imagine no one out there even used it right now, or at least did not create an issue and just swapped "function" with "operator" and then don't cared.

When I covered with unit tests and did some other tasks, I will come back to the createSchemalize/literal and try to dig deeper into e.g. "when do we need to quote and when not".
I could even think about to auto-quote certain keywords or throw errors on invalid data. But these could be even features in v8 potentially.

Copy link
Contributor

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

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

If this is only a step towards actually working, then it looks good to me.

@Shinigami92
Copy link
Collaborator Author

For the protocol and future reads: I currently do coverage unit tests to stabilize the "API" (functions and their signatures)

I will merge this MR when I'm done with the basic coverage, so that it is not in the middle of several test: * commits

@Shinigami92 Shinigami92 force-pushed the fix/swaps-operation-types branch from 584c1d4 to cc15515 Compare April 3, 2024 07:33
@Shinigami92 Shinigami92 added breaking change Cannot be merged when next version is not a major release and removed breaking change Cannot be merged when next version is not a major release labels Apr 3, 2024
@Shinigami92 Shinigami92 enabled auto-merge (squash) April 3, 2024 07:35
@Shinigami92 Shinigami92 disabled auto-merge April 3, 2024 07:35
@Shinigami92 Shinigami92 enabled auto-merge (squash) April 3, 2024 07:36
@Shinigami92 Shinigami92 disabled auto-merge April 3, 2024 07:36
@Shinigami92 Shinigami92 merged commit 3b97adc into main Apr 3, 2024
32 checks passed
@Shinigami92 Shinigami92 deleted the fix/swaps-operation-types branch April 3, 2024 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working p: 3-urgent Fix and release ASAP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Operation swaps operation and function types
2 participants