-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Update DB commands to support multiple gateways per slice #232
Conversation
b553d09
to
8a729db
Compare
496b217
to
cfa5dca
Compare
def call(name:, slice: nil, gateway: nil) | ||
if slice | ||
generator.call( | ||
key: name, | ||
namespace: slice, | ||
base_path: fs.join("slices", inflector.underscore(slice)), | ||
gateway: gateway | ||
) | ||
else | ||
generator.call( | ||
key: name, | ||
namespace: app.namespace, | ||
base_path: "app", | ||
gateway: gateway | ||
) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cllns a note for you — to be able to pass this extra gateway: gateway
arg when calling the generator, I had to copy the entire #call
implementation from the base generate command class. It would be good if we could allow individual generate command classes to be able to provide extra args to the generator without having to do this. An opportunity for a refactor in the future?
def table_exists?(slice, table_name) | ||
slice["db.gateway"].connection | ||
.fetch("PRAGMA table_info(#{table_name})") | ||
.to_a.any? | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being able to replace these with database-specific methods with a single e.g. Hanami.app["db.gateway"].connection.tables.include?(:posts)
invocation is so much nicer. I wish I had explored Sequel's API a little more before I wrote these methods in the first place!
8ed9569
to
7ad8e6c
Compare
Update the CLI for the DB gateway support introduced in hanami/hanami#1452:
Add
--gateway
option to the following CLI commands:db structure dump
db structure load
db create
db drop
db migrate
db version
generate migration
These commands will operate on an individual gateway when the
--gateway
is given. Otherwise, they will operate on all the gateways for a given app or slice (or the app and all slices) based on the other args given, as before.The above commands work with the following new file structures:
config/db/[gateway_name]_migrate/
directoriesconfig/db/[gateway_name]_structure.sql
The
db prepare
anddb seed
commands do not support a--gateway
option. This is because these commands are intended to operate on an app or slice as a whole. For example, there is only onedb/seeds.rb
file for a slice, and it should seed the tables across the slice's gateways as appropriate.