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

Feature request: CockroachDB support #990

Closed
2 tasks done
glerchundi opened this issue Aug 17, 2018 · 18 comments
Closed
2 tasks done

Feature request: CockroachDB support #990

glerchundi opened this issue Aug 17, 2018 · 18 comments
Labels
rfc A request for comments to discuss and share ideas.
Milestone

Comments

@glerchundi
Copy link
Contributor

glerchundi commented Aug 17, 2018

I'm evaluating Hydra v1.0.0-beta.8 and its compatibility with CockroachDB and I can confirm that except for two issues, things are working properly.

These two issues are:

WDYT, are you open to include CockroachDB support?

Update:

It seems like CockroachDB people is working on adding support for ALTER TABLE ... ALTER COLUM ... SET NOT NULL, take a look at cockroachdb/cockroach#37554.

@aeneasr
Copy link
Member

aeneasr commented Aug 19, 2018

I really want to avoid having another migration table like here. I also suspect that the two issues you mentioned wont be the only ones. I'm not sure how well CockroachDB works with SQL and specifically more complex join and lock statements. As most cloud providers support manages postgres and mysql at very low cost (but not cockroach), adding cockroach is not a priority for this project.

@glerchundi
Copy link
Contributor Author

I really want to avoid having another migration table like here.

The idea is to have the same migration table as the postgres one, I'm aligned with you here.

I also suspect that the two issues you mentioned wont be the only ones.

CockroachDB is working hard making everything pg-compat so if something doesn't work it should be fixed in the upstream and not here.

I'm not sure how well CockroachDB works with SQL and specifically more complex join and lock statements.

Can you point me to concrete SQL sentences, the more complex one you can think of?

As most cloud providers support manages postgres and mysql at very low cost (but not cockroach)

Yeah, but CockroachDB is open-source (at least most of its features) and with a growing user base. Great PostgreSQL compatibility, automatic sharding (world-wide capable), NoSQL capabilities, Geo-Partitioning and cloud-native philosophy (no need for an operator to run inside a k8s cluster, for example) makes this a great database to start with.

adding cockroach is not a priority for this project.

Would you be open to do some reviews of further PRs at least?

Thanks for your time.

@aeneasr
Copy link
Member

aeneasr commented Aug 20, 2018

Can you point me to concrete SQL sentences, the more complex one you can think of?

Of course, this is a particularly nasty one.

CockroachDB is working hard making everything pg-compat so if something doesn't work it should be fixed in the upstream and not here.

With pg-flavoured SQL-compatibility it should be no work to get it working with this project. How far away are they from achieving that?

Would you be open to do some reviews of further PRs at least?

Review yes but no guarantee of merging. This is not about "oh I don't like nothing that isn't MySQL or PostgreSQL" or "I dismiss the upsides of the project". Instead the issue is that including this in master implies that we:

  1. Write and test proper migrations for feature versions for another database
  2. Are able to support people who use CDB and have issues with our database layer due to whatever (e.g. unsupported syntax)
  3. Actually know how to maintain and use CDB because we officially support it
  4. Work around issues in CDB which clutter the proper/easier to read SQL but might stay there because we are not following the project and don't know when specific issues will be addressed.

None of these four things are something we can currently afford wrt to resources. Depending on the PR it may be possible that we have an "implicit" compatibility with CDB, but if CDB specific issues are addressed in a new migration "table"/instruction or existing migrations change (would bring serious trouble) this can't be merged.

I am however happy to review a PR regarding this, maybe it's much less stuff that changes than I think it is.

@glerchundi
Copy link
Contributor Author

Of course, this is a particularly nasty one.

It can be more or less performant due to joins but I think that should work. Inner joins with a pattern matching which is also supported.

With pg-flavoured SQL-compatibility it should be no work to get it working with this project. How far away are they from achieving that?

They are fixing the issues one by one but my feeling is that they are not too far from having a huge list of statement compatibilities. Take a look to a list of database management tools here.

Review yes but no guarantee of merging. This is not about "oh I don't like nothing that isn't MySQL or PostgreSQL" or "I dismiss the upsides of the project". Instead the issue is that including this in master implies that we:

Write and test proper migrations for feature versions for another database
Are able to support people who use CDB and have issues with our database layer due to whatever (e.g. unsupported syntax)
Actually know how to maintain and use CDB because we officially support it
Work around issues in CDB which clutter the proper/easier to read SQL but might stay there because we are not following the project and don't know when specific issues will be addressed.
None of these four things are something we can currently afford wrt to resources. Depending on the PR it may be possible that we have an "implicit" compatibility with CDB, but if CDB specific issues are addressed in a new migration "table"/instruction or existing migrations change (would bring serious trouble) this can't be merged.

IMHO merging doesn't mean official support, as you said what about just implicit compatibility and test it out explicitly adding a note saying that "[...] although it seems CockroachDB to be working properly no official support is given"?

I am however happy to review a PR regarding this, maybe it's much less stuff that changes than I think it is.

Cool, no much time ATM but will do as soon as I can, lets discuss on the PR(s). Making proposals without promises are the most comforting jobs after all ;)

Thanks again,

@aeneasr
Copy link
Member

aeneasr commented Aug 20, 2018

IMHO merging doesn't mean official support, as you said what about just implicit compatibility and test it out explicitly adding a note saying that "[...] although it seems CockroachDB to be working properly no official support is given"?

That's not how this project works :) If we're including stuff in the codebase, it's supported. With implicit support I mean that there will be no extra migrations, integration, nor e2e tests that check if this actually works! This means that future upgrades might not work with CDB or break the database (very unlikely but possible). If we're making substantial code changes it means that it needs to be tested, and with tests we must maintain it. I hope you understand this reasoning here.

But again, if it's possible to do this without any funkiness, let's try it!

@aeneasr aeneasr added this to the unplanned milestone Aug 21, 2018
@Multiply
Copy link

Multiply commented Dec 4, 2018

For the migration part, would it hurt too badly to add a new column with the right settings, move data from old to new column, remove old column and rename new column to old's name?

@aeneasr
Copy link
Member

aeneasr commented Dec 4, 2018

That really depends, there are production instances with millions of tokens - depending on which table this touches that could cause some serious db downtime. Which one is it?

@Multiply
Copy link

Multiply commented Dec 4, 2018

So far it only seems to be hydra_client.
Another problem I stumbled into is changing primary keys, which doesn't seem to be supported by Cockroach either. (unless I'm doing something entirely wrong)

So my current take on the issue, would be to create new tables and migrate data over, which seems silly.

Essentially what I had to do, to make Hydra work with Cockroach, was to run the migrations on a normal Postgres installation, and then export the structure. Not ideal, but good enough for my use-case for now.

@aeneasr
Copy link
Member

aeneasr commented Dec 4, 2018

Which column is causing the trouble?

The latest patch introduces real primary keys (uint, serial) to all tables iirc.

@Multiply
Copy link

Multiply commented Dec 4, 2018

Migrations causing trouble:

  1. All columns with the ALTER COLUMN ... SET NOT NULL as mentioned in the ticket.
  2. All migrations dropping primary keys. Example

@aeneasr
Copy link
Member

aeneasr commented Dec 4, 2018

Ah ok, I see. I am more inclined now than I was back in August to have CockroachDB officially supported. The new migration layout would potentially allow to run different migrations for each database, so theoretically, we could add just one new migration file for cockroach db.

@Multiply
Copy link

Multiply commented Dec 4, 2018

Another problem I had while trying to figure out which migrations failed, is the fact that it's not telling me which line/query in the migration that failed, so I had to narrow it down myself.

Example right now:

Applying `jwk` SQL migrations...
Applied 0 `jwk` SQL migrations.
Applying `client` SQL migrations...
Applied 0 `client` SQL migrations.
Applying `consent` SQL migrations...
An error occurred while running the migrations: could not apply consent SQL migrations: Could not migrate sql schema, applied 0 migrations: pq: no data source matches prefix: hydra_oauth2_consent_request handling 7

I can easily find the file, but since it's a migration on the 'large' side, it's a bit tough to easily spot the failing one. I basically just run each query one by one, and fix it manually.

@lopezator
Copy link
Contributor

lopezator commented Mar 20, 2019

This given:

Ah ok, I see. I am more inclined now than I was back in August to have CockroachDB officially supported. The new migration layout would potentially allow to run different migrations for each database, so theoretically, we could add just one new migration file for cockroach db.

Would you be open to receive/review a PR adding support for CockroachDB? At least to discuss it.

I could propose some changes to accomplish this.

@aeneasr
Copy link
Member

aeneasr commented Mar 21, 2019

Yup!

@lopezator
Copy link
Contributor

I've been advancing on this, so I'll send a draft PR shortly, just to start the discussion :)

lopezator added a commit to lopezator/x that referenced this issue Mar 21, 2019
add support for cockroachdb, related to ory/hydra#990
@glerchundi
Copy link
Contributor Author

Great job @lopezator!

@aeneasr
Copy link
Member

aeneasr commented May 10, 2019

Resolved #1348

@aeneasr aeneasr closed this as completed May 10, 2019
@glerchundi
Copy link
Contributor Author

Woohoo! 🎉

@aeneasr aeneasr added rfc A request for comments to discuss and share ideas. and removed request labels Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfc A request for comments to discuss and share ideas.
Projects
None yet
Development

No branches or pull requests

4 participants