lib/arql/concerns/global_data_definition.rb in arql-0.3.31 vs lib/arql/concerns/global_data_definition.rb in arql-0.4.0

- old
+ new

@@ -157,11 +157,18 @@ # CREATE TEMPORARY TABLE long_query AS # SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id # # See also TableDefinition#column for details on how to create columns. def create_table(table_name, **options, &blk) - ActiveRecord::Base.connection.create_table(table_name, **options, &blk) + env_name = options[:env] + unless env_name + raise ArgumentError, ':env option is required' if Arql::App.instance.environments.size > 1 + + env_name = Arql::App.instance.environments.first + end + options = options.except(:env) + Arql::App.instance.definitions[env_name].connection.create_table(table_name, **options, &blk) end # Creates a new join table with the name created using the lexical order of the first two # arguments. These arguments can be a String or a Symbol. # @@ -199,11 +206,18 @@ # assembly_id bigint NOT NULL, # part_id bigint NOT NULL, # ) ENGINE=InnoDB DEFAULT CHARSET=utf8 # def create_join_table(table_1, table_2, column_options: {}, **options) - ActiveRecord::Base.connection.create_join_table(table_1, table_2, column_options, **options) + env_name = options[:env] + unless env_name + raise ArgumentError, ':env option is required' if Arql::App.instance.environments.size > 1 + + env_name = Arql::App.instance.environments.first + end + options = options.except(:env) + Arql::App.instance.definitions[env_name].connection.create_join_table(table_1, table_2, column_options, **options) end # Drops a table from the database. # # [<tt>:force</tt>] @@ -215,30 +229,50 @@ # # Although this command ignores most +options+ and the block if one is given, # it can be helpful to provide these in a migration's +change+ method so it can be reverted. # In that case, +options+ and the block will be used by #create_table. def drop_table(table_name, **options) - ActiveRecord::Base.connection.drop_table(table_name, **options) + env_name = options[:env] + unless env_name + raise ArgumentError, ':env option is required' if Arql::App.instance.environments.size > 1 + + env_name = Arql::App.instance.environments.first + end + options = options.except(:env) + Arql::App.instance.definitions[env_name].connection.drop_table(table_name, **options) end # Drops the join table specified by the given arguments. # See #create_join_table for details. # # Although this command ignores the block if one is given, it can be helpful # to provide one in a migration's +change+ method so it can be reverted. # In that case, the block will be used by #create_join_table. def drop_join_table(table_1, table_2, **options) - ActiveRecord::Base.connection.drop_join_table(table_1, table_2, **options) + env_name = options[:env] + unless env_name + raise ArgumentError, ':env option is required' if Arql::App.instance.environments.size > 1 + + env_name = Arql::App.instance.environments.first + end + options = options.except(:env) + Arql::App.instance.definitions[env_name].connection.drop_join_table(table_1, table_2, **options) end # Renames a table. # # rename_table('octopuses', 'octopi') # def rename_table(table_name, new_name) - ActiveRecord::Base.connection.rename_table(table_name, new_name) - end + env_name = options[:env] + unless env_name + raise ArgumentError, ':env option is required' if Arql::App.instance.environments.size > 1 + env_name = Arql::App.instance.environments.first + end + options = options.except(:env) + Arql::App.instance.definitions[env_name].connection.rename_table(table_name, new_name) + end end end end end