-
-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace DBAL layer with gobuffalo/pop (#130)
This is a major refactoring of the internal DBAL. After a successful proof of concept and evaluation of gobuffalo/pop, we believe this to be the best DBAL for Go at the moment. It abstracts a lot of boilerplate code away. As with all sophisticated DBALs, pop too has its quirks. There are several issues that have been discovered during testing and adoption: gobuffalo/pop#136 gobuffalo/pop#476 gobuffalo/pop#473 gobuffalo/pop#469 gobuffalo/pop#466 However, the upside of moving much of the hard database/sql plumbing into another library cleans up the code base significantly and reduces complexity. As part of this change, the "ephermal" DBAL ("in memory") will be removed and sqlite will be used instead. This further reduces complexity of the code base and code-duplication. To support sqlite, CGO is required, which means that we need to run tests with `go test -tags sqlite` on a machine that has g++ installed. This also means that we need a Docker Image with `alpine` as opposed to pure `scratch`. While this is certainly a downside, the upside of less maintenance and "free" support for SQLite, PostgreSQL, MySQL, and CockroachDB simply outweighs any downsides that come with CGO.
- Loading branch information
Showing
152 changed files
with
4,029 additions
and
4,761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ tmp | |
scripts | ||
.idea | ||
.git/ | ||
database.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
development: | ||
url: sqlite://a/b | ||
|
||
sqlite: | ||
url: sqlite://a/b | ||
|
||
postgres: | ||
url: postgres://a/b | ||
|
||
mysql: | ||
url: mysql://tcp(a)/b?parseTime=true&multiStatements=true | ||
|
||
cockroach: | ||
url: crdb://a/b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# SQL Migrations | ||
|
||
To create a new [fizz](https://gobuffalo.io/en/docs/db/fizz/) migration run in the project root: | ||
|
||
``` | ||
$ soda generate fizz -c ./contrib/sql/.soda.yml -p ./contrib/sql/migrations [name] | ||
``` | ||
|
||
To create SQL migrations, target each database individually and run | ||
|
||
``` | ||
$ soda generate sql -e mysql -c ./contrib/sql/.soda.yml -p ./contrib/sql/migrations [name] | ||
$ soda generate sql -e sqlite -c ./contrib/sql/.soda.yml -p ./contrib/sql/migrations [name] | ||
$ soda generate sql -e postgres -c ./contrib/sql/.soda.yml -p ./contrib/sql/migrations [name] | ||
$ soda generate sql -e cockroach -c ./contrib/sql/.soda.yml -p ./contrib/sql/migrations [name] | ||
``` | ||
|
||
or, alternative run | ||
|
||
``` | ||
$ soda generate sql -c ./contrib/sql/.soda.yml -p ./contrib/sql/migrations | ||
``` | ||
|
||
and remove the `sqlite` part from the newly generated file to create a SQL migrations that works with all | ||
aforementioned databases. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
drop_table("identities") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
create_table("identities") { | ||
t.Column("id", "uuid", {primary: true}) | ||
t.Column("traits_schema_url", "string", {"size": 2048}) | ||
t.Column("traits", "json") | ||
|
||
t.Timestamps() | ||
} | ||
|
||
create_table("identity_credential_types") { | ||
t.Column("id", "uuid", {primary: true}) | ||
t.Column("name", "string", { "size": 32 }) | ||
|
||
t.DisableTimestamps() | ||
} | ||
|
||
add_index("identity_credential_types", "name", {"unique": true}) | ||
|
||
create_table("identity_credentials") { | ||
t.Column("id", "uuid", {primary: true}) | ||
t.Column("config", "json") | ||
|
||
t.Column("identity_credential_type_id", "uuid", { "size": 32 }) | ||
t.Column("identity_id", "uuid") | ||
|
||
t.Timestamps() | ||
|
||
t.ForeignKey("identity_id", {"identities": ["id"]}, {"on_delete": "cascade"}) | ||
t.ForeignKey("identity_credential_type_id", {"identity_credential_types": ["id"]}, {"on_delete": "cascade"}) | ||
} | ||
|
||
create_table("identity_credential_identifiers") { | ||
t.Column("id", "uuid", {primary: true}) | ||
t.Column("identifier", "string", {"size": 255}) | ||
t.Column("identity_credential_id", "uuid") | ||
|
||
t.Timestamps() | ||
|
||
t.ForeignKey("identity_credential_id", {"identity_credentials": ["id"]}, {"on_delete": "cascade"}) | ||
} | ||
|
||
add_index("identity_credential_identifiers", "identifier", {"unique": true}) |
Oops, something went wrong.