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 Cockroach Dialect #12346
base: main
Are you sure you want to change the base?
Add Cockroach Dialect #12346
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #12346 +/- ##
==========================================
- Coverage 60.68% 60.67% -0.01%
==========================================
Files 1495 1495
Lines 36878 36884 +6
Branches 7359 7363 +4
==========================================
Hits 22380 22380
- Misses 12417 12421 +4
- Partials 2081 2083 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
You can use |
Ya was waiting for newest npm publish, which happened 7 mins ago Still will have to migrate to knex 1.0 for the other dbs |
(This PR is still full of logs but you can use this branch and use yarn link to test it on a Strapi instance)
I just migrated to knex 1.0.2 and implemented the alterNullable and that fixed the drop null on id column. (https://github.com/Cpaczek/strapi/blob/8a3b09759c76c80a996f99b76b3f7cdb0ff0debe/packages/core/database/lib/schema/builder.js#L307) However I am running into a new issue. On knex .95.x our issue outside of the drop nullable was the int -> int on column types now its the following. I also "implemented" alterType by setting it to false on all
not sure if I have to selectively change if alterType is true of false depending on the change. this is just a very rough test. Still doing research. With alterType = false
With alterType = true
With it set to true looks like its trying to use a cdb experimental feature: Experimental alter column in use, see issue: cockroachdb/cockroach#49329 What I think may be the root of the problem is this:The errors above happen when I am trying to add a new collection. You can see that it wants to add the table just fine however pretty much every table has updated columns which I am not sure why yet. Why would adding a new collection modify the so many different other table's columns. Pretty sure there is something really wrong with the diff function within Strapi (https://github.com/Cpaczek/strapi/blob/8a3b09759c76c80a996f99b76b3f7cdb0ff0debe/packages/core/database/lib/schema/diff.js#L325) All of these tables get updated just because I added a new collection:Makes no sense why the schema of these tables need to be updated. @derrickmehaffy Any idea why Strapi wants to change so many table's schemas? There also may be issues unrelated to cockroach db becuase of updating to knex 1.0.Breaking changes |
I have been following along with this as well. The behaviour seems like whenever another table is added which has a foreign key, the table owning the foreign key is updated for no reason. For example, if I have table A which references a column on table B. When table A is created, an update is issued to table B (which doesn't change anything at all). |
I don't have any ideas, @alexandrebodin would need to weigh in here as he wrote basically all of this himself
This would be my guess though as we added FQ now to basically everything (for good reason) but I don't know why doing so would mean doing updates if nothing changed. I would assume our diff code could be improved but I haven't dug that deep into it myself as I've been slammed with multiple other topics lately. |
Are there any existing plans to migrate to knex v1? I am planning on doing this in this PR but I was wondering if that was already in the works. |
We didn't have any specific plans but I don't think we have any specific arguments not to either. More so wasn't a concern because we didn't need anything in the update yet, but if adding cockroach needs it, I don't see why we can't. So long as we don't introduce any breaking changes. |
Afaik the only thing that would have to be changed from the user's perspective is the SQLite driver and that is rarely using in prod anyway, and that is probably for the better as its not longer supported. There are a lot of cool new features in the 1.0 release as well https://github.com/knex/knex/releases |
Did they finally drop mapbox's SQLite package |
Yes, I think they support 2 driver's now, vscode's and something else |
So we will need to change the default SQLite driver we install when someone chooses quickstart. |
VSCode sqlite one is a drop-in replacement for mapbox, though. |
We still have a method on project generation that adds the specific database package to the main package.json, usually sqlite3, MySQL, or pg. I'll find the generator logic and point it out after my lunch. |
Here we go, this is where we set the db-client + version to set in the new project's package.json:
|
I've got a draft PR open to work on upgrading knex: #12557 |
I'm excited about this 😊 |
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/mongodb-compatibility-delayed-on-v4/4549/135 |
Hey @alexandrebodin I think this PR is pretty much ready for review, just added the integration tests and they are Edit: To test this PR here are some commands to get you up and running with a CRDB docker container. docker volume create roach-single docker run --name=roach-single -p 26257:26257 -p 8080:8080 -v "roach-single:/cockroach/cockroach-data" cockroachdb/cockroach:latest start-single-node --insecure Get an SQL shell docker exec -it roach-single ./cockroach sql --url="postgresql://root@127.0.0.1:26257/defaultdb?sslmode=disable" Strapi DB Config connection: {
client: 'cockroachdb',
connection: {
host: env('DATABASE_HOST', '127.0.0.1'),
port: env.int('DATABASE_PORT', 26257),
database: env('DATABASE_NAME', 'defaultdb'),
user: env('DATABASE_USERNAME', 'root'),
password: env('DATABASE_PASSWORD', ''),
ssl: env.bool('DATABASE_SSL', false)
},
debug: false, //optional
}, Current Status of this PR:Currently everything is working and I have There are a few things to note:Altering Column TypesCockroach db doesn't support altering column type. i.e going from Experimental StatusTalking with @derrickmehaffy it seems like Strapi will support this experimentally first, so I have added very big red letters in the startup log saying that its experimental and big red notice in my docs PR saying that its experimental. I was talking with derrick and we were wondering if we should require an env var like Race ConditionsI also have run into some race conditions with how you are assigning orders for relations you can read about that more here #15558 the issue with CRDB specifically is that it enforces the unique constraint on the link tables for relation order whereas the other databases seem to be a bit looser when it comes to this constraint. This won't be a problem for most Strapi apps but if you have any horizontal scaling it could cause an issue, or if you are doing stuff like promise.all() like what I fixed in the user and permissions plugin. See the issue for more details. Huge thanks to @Boegie19 without him this PR would of never been completed. As always I am open to any changes that the Strapi team needs and I'm always available to hop on a call if you want to discuss. Hoping to get this merged soon, There is already at least 1 person using the code on the branch to add cockroach support to their project. |
Hi @cpaczek, I was just wondering why this stalled out and if it's ever getting merged |
@selfagency The answer is most likely no this will never happen. unless strapi does the required changes to make it work. This causes issues with lots of race conditions in strapi that Read Committed Isolation Level would not care about but Serializable Isolation Level will cancel the saving in the DB if any of the race conditions happen. After this where to be fixed we still have. |
Cockroach db has added read committed isolation levels as of Jan 17 2024 in public preview meaning this will allow support for Cockroach to be used with Strapi. |
@derrickmehaffy ill be updating this pr to be up to date with main, can you reopen issue #11738 |
You should target develop I believe now |
To test this PR here are some commands to get you up and running with a CRDB docker container.
docker run --name=roach-single -p 26257:26257 -p 8080:8080 -v "roach-single:/cockroach/cockroach-data" cockroachdb/cockroach:latest start-single-node --insecure
Get an SQL shell
Strapi DB Config
fixes #11738