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 for createViewOrReplace and its support for sqlite3 #4856

Merged
merged 3 commits into from Jan 14, 2022

Conversation

thebrownfox
Copy link
Contributor

@thebrownfox thebrownfox commented Nov 26, 2021

Related issues:
Closes #4854
Closes #4855

Copy link
Collaborator

@OlivierCavadenti OlivierCavadenti left a comment

Choose a reason for hiding this comment

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

Thanks for the report + PR ! Tests fails

test/integration2/schema/views.spec.js Show resolved Hide resolved
test/unit/schema-builder/sqlite3.js Outdated Show resolved Hide resolved
@OlivierCavadenti
Copy link
Collaborator

@kibertoad maybe could be nice to add this in 0.95.15 ?

@kibertoad
Copy link
Collaborator

sure, sounds good

@OlivierCavadenti
Copy link
Collaborator

@kibertoad I push returns, if you can take a look.

@thebrownfox
Copy link
Contributor Author

@OlivierCavadenti sorry, I was busy and then sick. Have you sorted it out? BTW I was thinking whether the functionality could behave the same as in sqlite3 across all dbs. In postgres, when you use the builtin functionality, it needs to have the same columns in same order and new ones at the end. I ended up using drop and create anyway.

await Model.knex().schema.dropViewIfExists(dBViewName);

dbView = await Model.knex().schema.createView(
    dBViewName,
    (view) => {
        view.as(Model.knex().raw(query));
    }
);

@OlivierCavadenti
Copy link
Collaborator

OlivierCavadenti commented Dec 10, 2021

@OlivierCavadenti sorry, I was busy and then sick. Have you sorted it out? BTW I was thinking whether the functionality could behave the same as in sqlite3 across all dbs.

No problem ^^.

In postgres, when you use the builtin functionality, it needs to have the same columns in same order and new ones at the end.

I am afraid I dont understand, you need to create new view but with same columns in same order when you use createViewOrReplace ? I dont test that, but it throws an error ?

EDIT : I see the documentation (it seems good pratice :D) and I see the problem:

CREATE OR REPLACE VIEW is similar, but if a view of the same name already exists, it is replaced. The new query must generate the same columns that were generated by the existing view query (that is, the same column names in the same order and with the same data types), but it may add additional columns to the end of the list. The calculations giving rise to the output columns may be completely different.

@OlivierCavadenti
Copy link
Collaborator

BTW I was thinking whether the functionality could behave the same as in sqlite3 across all dbs.

In postgres, when you use the builtin functionality, it needs to have the same columns in same order and new ones at the end.

By the way, I assume this limitation in PostgreSQL (need replace with same columns, same order) it's to dont break all existing queries that query the view you replace.

In my opinion, it's better to dont change existing queries 'create or replace view' and so have this safe behavior, and put in Knex documentation what you are saying : the difference between sqlite3 and other dbs.

@kibertoad what do think about that ?

@kibertoad
Copy link
Collaborator

@OlivierCavadenti I agree, handling it via documentation is a better path.

@OlivierCavadenti
Copy link
Collaborator

@kibertoad we will put this one on 1.0.0 (with backport in 0.95.X) or we will merge it after the 1.0.0 tag ?

@kibertoad
Copy link
Collaborator

@OlivierCavadenti I'm OK with merging it in 1.0.0 if you prefer it that way.

@kibertoad kibertoad merged commit 3f0ec9f into knex:master Jan 14, 2022
@kibertoad
Copy link
Collaborator

kibertoad commented Jan 14, 2022

@OlivierCavadenti Any last minute changes, or I can start releasing 1.0.0 in an hour or so?

@OlivierCavadenti
Copy link
Collaborator

@OlivierCavadenti Any last minute changes, or I can start releasing 1.0.0 in an hour or so?

I dont see anything else. I will track carefully any issues if anything need to be fix before/after the 1.0.0 tag :D.

@kibertoad
Copy link
Collaborator

Released in 1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support createViewOrReplace for sqlite3 createViewOrReplace - wrong syntax
3 participants