Module: Cell::CloneSchema
- Defined in:
- lib/cell/clone_schema.rb
Class Method Summary collapse
- .clone_schema(src, dst) ⇒ Object
- .connection ⇒ Object
- .copy_schema_migrations_to(dst) ⇒ Object
- .function_definition ⇒ Object
- .install_function! ⇒ Object
Class Method Details
.clone_schema(src, dst) ⇒ Object
11 12 13 14 15 |
# File 'lib/cell/clone_schema.rb', line 11 def self.clone_schema(src, dst) connection.execute <<~SQL SELECT public.clone_schema(#{connection.quote(src)}, #{connection.quote(dst)}, TRUE) SQL end |
.connection ⇒ Object
6 7 8 |
# File 'lib/cell/clone_schema.rb', line 6 def self.connection ::ActiveRecord::Base.connection end |
.copy_schema_migrations_to(dst) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cell/clone_schema.rb', line 18 def self.copy_schema_migrations_to(dst) Cell::Meta.with_schema(dst, exclusive: true) do ::ActiveRecord::SchemaMigration.create_table end connection.execute <<~SQL INSERT INTO #{connection.quote_schema_name(dst)}.schema_migrations SELECT * from schema_migrations SQL end |
.function_definition ⇒ Object
38 39 40 |
# File 'lib/cell/clone_schema.rb', line 38 def self.function_definition FUNCTION_DEFINITION end |
.install_function! ⇒ Object
30 31 32 33 34 35 |
# File 'lib/cell/clone_schema.rb', line 30 def self.install_function! @created ||= begin connection.execute(function_definition) true end end |