Module: PlanetscaleRails::Migration::Current
- Defined in:
- lib/planetscale_rails/migration.rb
Instance Method Summary collapse
-
#create_table(table_name, **options) ⇒ Object
Allows users to set the ‘keyspace` option in their migration file or via an ENV var PLANETSCALE_DEFAULT_KEYSPACE.
Instance Method Details
#create_table(table_name, **options) ⇒ Object
Allows users to set the ‘keyspace` option in their migration file or via an ENV var PLANETSCALE_DEFAULT_KEYSPACE. If the migration is being run against PlanetScale (i.e. `ENABLE_PSDB` is set), then we prepend the keyspace to the table name.
For local MySQL databases, the keyspace is ignored.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/planetscale_rails/migration.rb', line 10 def create_table(table_name, **) keyspace = [:keyspace] if keyspace.blank? && ENV["PLANETSCALE_DEFAULT_KEYSPACE"].present? keyspace = ENV["PLANETSCALE_DEFAULT_KEYSPACE"] log_keyspace_usage(keyspace) end if ENV["ENABLE_PSDB"] && keyspace.present? table_name = "#{keyspace}.#{table_name}" end super(table_name, **.except(:keyspace)) end |