Module: ActiveRecord::BigQueryMigrator

Defined in:
lib/active_record/connection_adapters/bigquery_adapter.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/active_record/connection_adapters/bigquery_adapter.rb', line 260

def self.included base
  #overload class methods
  base.instance_eval do
    def get_all_versions
      SchemaMigration.all.map { |x| x["version"].to_i }.sort
    end

    def current_version
      sm_table = schema_migrations_table_name
      migration_file_pwd = Dir.pwd + "/db/schema_migrations.json"

      if File.exists?(migration_file_pwd)
        get_all_versions.max || 0
      else
        0
      end
    end

    def needs_migration?
      current_version < last_version
    end

    def last_version
      get_all_versions.min.to_i
      #last_migration.version
    end

    def last_migration #:nodoc:
      migrations(migrations_paths).last || NullMigration.new
    end

  end
  #overload instance methods
  base.class_eval do
    def current_version
      migrated.max || 0
    end

    def current_migration
      migrations.detect { |m| m["version"] == current_version }
    end

    #def migrated
    #  @migrated_versions ||= Set.new(self.class.get_all_versions)
    #end

    private

      def record_version_state_after_migrating(version)

        if down?
          migrated.delete(version)
          ActiveRecord::SchemaMigration.delete_version(:version => version.to_s)
        else
          migrated << version
          ActiveRecord::SchemaMigration.create!(:version => version.to_s)
        end
      end
  end
end