You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you've used rails in the past, chances are you've seen this db/schema.rb file. It's a snapshot of current database schema that written in ruby DSL. The dumped schema is database agnostic, and can be used again to restore database schema, something that very useful in CI environment, where running hundreds of migrations one by one for every test build will consume a lot of time. Not only that, this file is also useful during peer review, to see what's the result of migration.
In REL, we would like to have something similar, but in go. It's potential usage is not limited to loading schema in CI environment (which we don't need anyway given we have reltest package 😏 ), but also the following:
Validate record modification in reltest package. eg: making sure Set("name", "your name") is properly setting to an existing field in database with the correct type.
Validate query in reltest package. eg: making sure where.Eq("name", "your name") is a valid query against a valid field with valid type and operator.
As a foundation for type safe query builder generator, that can extend REL's query builder.
Implementation
Adapter Updates
Two new function needs to be added on each adapter to support this feature.
Implementation of each database might be completely different, so we may not be able to reuse Load and Dump method across all adapter.
typeAdapterinterface {
// ...// load schema back to database.// Probably will call Apply, after setting some variable (ex: disabling foreign key check)Load(ctx context.Context, schemaSchema) error// Dump database schema as plain go struct.Dump(ctx context.Context) (Schema, error)
}
Dump Result
// file: db/schema.gopackage db
// TBD
CLI
rel dump - Dump database schema to db/schema.go.
rel load - Load db/schema.go to database.
rel migrate and rel rollback - Modification for this to always call dump after command executed.
Tasks
SQLite3 Adapter Dump and Load function.
MySQL Adapter Dump and Load function.
Postgres Adapter Dump and Load function.
Migrator function to translate Adapter dump function result to golang code in db/schema.go as migration DSL.
rel dump command.
rel load command.
rel migrate and rel rollback modification.
The text was updated successfully, but these errors were encountered:
Background
If you've used rails in the past, chances are you've seen this
db/schema.rb
file. It's a snapshot of current database schema that written in ruby DSL. The dumped schema is database agnostic, and can be used again to restore database schema, something that very useful in CI environment, where running hundreds of migrations one by one for every test build will consume a lot of time. Not only that, this file is also useful during peer review, to see what's the result of migration.In REL, we would like to have something similar, but in go. It's potential usage is not limited to loading schema in CI environment (which we don't need anyway given we have
reltest
package 😏 ), but also the following:reltest
package. eg: making sureSet("name", "your name")
is properly setting to an existing field in database with the correct type.reltest
package. eg: making surewhere.Eq("name", "your name")
is a valid query against a valid field with valid type and operator.Implementation
Adapter Updates
Two new function needs to be added on each adapter to support this feature.
Implementation of each database might be completely different, so we may not be able to reuse Load and Dump method across all adapter.
Dump Result
CLI
rel dump
- Dump database schema todb/schema.go
.rel load
- Loaddb/schema.go
to database.rel migrate
andrel rollback
- Modification for this to always call dump after command executed.Tasks
db/schema.go
as migration DSL.rel dump
command.rel load
command.rel migrate
andrel rollback
modification.The text was updated successfully, but these errors were encountered: