Module: Cell::Ext::Migration

Defined in:
lib/cell/ext/migration.rb

Defined Under Namespace

Modules: CommandRecorderFilter, ContextTracker, MetadataIntercept

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.intercept(methods) ⇒ Object

We intercept these methods, and only execute if appropriate according to execute_ddl?



93
94
95
96
97
98
99
# File 'lib/cell/ext/migration.rb', line 93

def self.intercept(methods)
  methods.each do |method|
    define_method(method) do |*args, &block|
      super(*args, &block) if execute_ddl?
    end
  end
end

Instance Method Details

#exec_migration(con, direction) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/cell/ext/migration.rb', line 141

def exec_migration(con, direction)
  if ! targeted?
    with_context(:global, global_schema) do
      super
    end

    with_context(:prototype, prototype_schema) do
      super
    end
  else
    with_context(:target, tenant_schema, exclusive: true) do
      super
    end
  end
end

#global_schemaObject



115
116
117
# File 'lib/cell/ext/migration.rb', line 115

def global_schema
  Meta.global_schema
end

#initialize_cell!Object

This is our super-special initialization function.



136
137
138
139
# File 'lib/cell/ext/migration.rb', line 136

def initialize_cell!
  CloneSchema.install_function!
  execute "CREATE SCHEMA #{connection.quote_schema_name(prototype_schema)}"
end

#prototype_schemaObject



119
120
121
# File 'lib/cell/ext/migration.rb', line 119

def prototype_schema
  Meta.prototype_schema
end

#targetObject



127
128
129
# File 'lib/cell/ext/migration.rb', line 127

def target
  Model.current
end

#targeted?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/cell/ext/migration.rb', line 131

def targeted?
  !! target
end

#tenant_schemaObject



123
124
125
# File 'lib/cell/ext/migration.rb', line 123

def tenant_schema
  target.schema_name
end