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

all: add support for cockroachdb #40

Merged
merged 1 commit into from
May 2, 2019
Merged

Conversation

lopezator
Copy link
Contributor

add support for cockroachdb

Related MR

This would need to be merged before: ory/hydra#1348

Proposed changes

Add support for cockroachdb in x.

@lopezator
Copy link
Contributor Author

lopezator commented Apr 16, 2019

There is some tricky game here, because the used DSN: cockroach:// and the real DSN to use in lib/pq: postgres:// have to be converted in many places, but I implemented in the same way as mysql:// prefix adding and removal is done inside the code, to keep the consistency with the current code and without changing it too much.

CC \ @aeneasr

@lopezator lopezator force-pushed the feature/crdb branch 13 times, most recently from 5cd9c1b to 2ec34ea Compare April 17, 2019 16:15
@lopezator
Copy link
Contributor Author

PTAL @aeneasr

@aeneasr
Copy link
Member

aeneasr commented Apr 18, 2019

Thank you for this PR and your hard work!

I'm wondering if introducing a wrapper to sqlx.DB is really the best solution here? First we introduce a couple of breaking changes which will require updates in all dependent code and second I'm not entirely sure why we're wrapping e.g. NamedExecContext but not other methods?

I'm not sure if I'm missing something very critical here, but wouldn't it be enough to just update this method so that it, for input cockroach://foo:[email protected]:1234/db?k=v returns postgres://foo:[email protected]:1234/db?k=v? That should solve all downstream issue, right?

The only issue I see is in migrations where we're using the db.DriverName() to get the proper migration (example from hydra):

 migrate.Exec(m.DB.DB, m.DB.DriverName(), Migrations[dbal.Canonicalize(m.DB.DriverName())], migrate.Up)

However, for that we could probably come up with an idea to solve that another way (e.g. using the configuration provider to get the full DSN, or by updating the CreateSchema() method to CreateSchema(driver string, db *sqlx.DB)).

What do you think?

@lopezator lopezator force-pushed the feature/crdb branch 2 times, most recently from 8a07cd0 to 6f62cf9 Compare April 23, 2019 16:20
@lopezator
Copy link
Contributor Author

Wrapper removed, PTAL @aeneasr

@aeneasr
Copy link
Member

aeneasr commented Apr 25, 2019

Nice! This looks much cleaner I think - what do you think? I have to run this locally to assure that everything works as expected but I don't think that there will be any changes necessary!

@lopezator
Copy link
Contributor Author

Yep, agree, easier to understand. I don't have more changes in mind, so if you are ok with this, me too!

@aeneasr aeneasr self-requested a review April 29, 2019 10:35
@aeneasr aeneasr self-assigned this Apr 29, 2019
Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Great work! Just a few nitpics :)

log.Fatalf("Could not start resource: %s", err)
}

urls := bootstrap("postgres://root@localhost:%s/defaultdb?sslmode=disable", "26257/tcp", "postgres", pool, resource)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't that be cockroach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can't be cockroach, because we need the "real" dsn (from GO driver perspective) inside the bootstrap function, for a successful sql.Open to happen.

I just applied the same logic it's been applied with mysql (send the DSN without mysql://, then add it after the bootstrap function).

Unless I'm missing something here the only thing we can do it's just change the place of the replace to inside the boostrap function with a switch/case (for mysql and cockroach) instead of doing it individually inside bootstrapMySQL() and bootstrapCockroach().

See here:

https://github.com/ory/x/blob/master/sqlcon/connector_test.go#L299-L302

And here:

https://github.com/ory/x/blob/master/sqlcon/connector_test.go#L337

@lopezator lopezator force-pushed the feature/crdb branch 2 times, most recently from 3190842 to c6b28e3 Compare April 30, 2019 07:33
@lopezator
Copy link
Contributor Author

Changes applied, PTAL and tell some if you find something more @aeneasr !

add support for cockroachdb

Signed-off-by: David López <[email protected]>
@aeneasr
Copy link
Member

aeneasr commented May 2, 2019

THank you so much!

@aeneasr aeneasr merged commit 1d07df7 into ory:master May 2, 2019
@lopezator lopezator deleted the feature/crdb branch May 2, 2019 14:15
@MateusAmin MateusAmin mentioned this pull request Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants