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

Fixed error when setting Oracle column to not null #8111

Merged
merged 7 commits into from Sep 22, 2021
Merged

Fixed error when setting Oracle column to not null #8111

merged 7 commits into from Sep 22, 2021

Conversation

aidenfoxx
Copy link
Contributor

@aidenfoxx aidenfoxx commented Sep 17, 2021

Normalized migrations so Oracle lines up with other schemas, and also fixed down migrations which didn't re-apply NOT NULL constraint.

@aidenfoxx
Copy link
Contributor Author

So after testing a fresh install I do get the error:

[Error] alter table "directus_webhooks" modify ("collections" NOT NULL) - ORA-01442: column to be modified to NOT NULL is already NOT NULL

I tried testing with SQLite to see if this was the case for other schemas, and was surprised to discover [Error] .dropNullable is not supported for SQLite.. I'm setting this PR to draft until I figure out what is going on with this migration.

@aidenfoxx aidenfoxx marked this pull request as draft September 17, 2021 12:11
@aidenfoxx
Copy link
Contributor Author

Okay, so I see the issue. When I updated the migration 20210312A-webhooks-collections-text.ts that allowed Oracle to install, I retained the NOT NULL constraint. I didn't consider that Knex wouldn't retain the NOT NULL constraint when changing the field type: table.text('collections').alter();.

But to that point, the "down" migration in 20210312A-webhooks-collections-text.ts is also incorrect as it does not re-enable the NOT NULL constraint. The same applies to 20201105B-change-webhook-url-type.ts.

So I think the fix is to:

  • Ignore Oracle for this migration, since it is already NOT NULL
  • Update the down methods of 20210312A-webhooks-collections-text.ts and 20201105B-change-webhook-url-type.ts to set the columns back to NOT NULL
  • Add a new migration to set directus_webhooks.url to NOT NULL

Does that sound alright @rijkvanzanten?

@rijkvanzanten
Copy link
Member

I tried testing with SQLite to see if this was the case for other schemas, and was surprised to discover [Error] .dropNullable is not supported for SQLite.. I'm setting this PR to draft until I figure out what is going on with this migration.

Woooooooooooo @nickrum we found a gap in the SQLite implementation 😵 🔫

I didn't consider that Knex wouldn't retain the NOT NULL constraint when changing the field type: table.text('collections').alter();.
But to that point, the "down" migration in 20210312A-webhooks-collections-text.ts is also incorrect as it does not re-enable the NOT NULL constraint. The same applies to 20201105B-change-webhook-url-type.ts.

Ohhhhhh interesting

Update the down methods of 20210312A-webhooks-collections-text.ts and 20201105B-change-webhook-url-type.ts to set the columns back to NOT NULL

While it's technically not really kosher to retroactively change migrations, I think this is enough of an edge case in oracle specifically to do it. I'd go with this direction 👍🏻

@nickrum
Copy link
Member

nickrum commented Sep 17, 2021

Woooooooooooo @nickrum we found a gap in the SQLite implementation 😵 🔫

Yeah, those functions have only been added a few weeks ago. Shouldn't be too hard to add SQLite support. I can take care of that if you want, @aidenfoxx.

@aidenfoxx
Copy link
Contributor Author

aidenfoxx commented Sep 18, 2021

@nickrum I mentioned to their dev that I'd take a look this weekend if I get the chance. But if you don't see a PR by Monday then you're free to jump on it (assuming you've not already started). 😄

It shouldn't be required for this fix though since Oracle is already NOT NULL.

@aidenfoxx aidenfoxx marked this pull request as ready for review September 20, 2021 15:02
api/package.json Outdated Show resolved Hide resolved
@aidenfoxx
Copy link
Contributor Author

aidenfoxx commented Sep 20, 2021

  • Updated the migrations 20210312A-webhooks-collections-text.ts and 20201105B-change-webhook-url-type.ts to re-apply the NOT NULL constraint on down
  • Skip the 20210907A-webhooks-collections-not-null.ts migration for Oracle since it's already NOT NULL due to my incompetence 😝
  • Added new migration to set directus_webhooks.url to NOT NULL as I believe it should be

Tested migrations up and down against MySQL, SQLite and Oracle.

@aidenfoxx
Copy link
Contributor Author

Also, just a heads up @rijkvanzanten and @nickrum. I added setNullable and dropNullable support to SQLite, so we can start using those methods once that's released.

knex/knex#4684

@rijkvanzanten rijkvanzanten added this to the v9.0.0-rc.95 milestone Sep 22, 2021
@rijkvanzanten rijkvanzanten merged commit c6eda9f into directus:main Sep 22, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants