Class: DynamicMigrations::Postgres::Server::Database::Differences::ToMigrations

Inherits:
Object
  • Object
show all
Includes:
Extensions, Schemas, Schemas::Enums, Schemas::Functions, Schemas::Tables, Schemas::Tables::Columns, Schemas::Tables::ForeignKeyConstraints, Schemas::Tables::Indexes, Schemas::Tables::PrimaryKey, Schemas::Tables::Triggers, Schemas::Tables::UniqueConstraints, Schemas::Tables::Validations
Defined in:
lib/dynamic_migrations/postgres/server/database/differences/to_migrations.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/extensions.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/enums.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/functions.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/columns.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/indexes.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/triggers.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/primary_key.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/validations.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/unique_constraints.rb,
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/foreign_key_constraints.rb

Defined Under Namespace

Modules: Extensions, Schemas Classes: UnexpectedDatabaseObjectError, UnexpectedDifferencesObjectError

Instance Method Summary collapse

Methods included from Schemas::Tables::Validations

#process_validation, #process_validations

Methods included from Schemas::Tables::UniqueConstraints

#process_unique_constraint, #process_unique_constraints

Methods included from Schemas::Tables::Triggers

#process_trigger, #process_triggers

Methods included from Schemas::Tables::PrimaryKey

#process_primary_key

Methods included from Schemas::Tables::Indexes

#process_index, #process_indexes

Methods included from Schemas::Tables::ForeignKeyConstraints

#process_foreign_key_constraint, #process_foreign_key_constraints

Methods included from Schemas::Tables::Columns

#process_column, #process_columns

Methods included from Schemas::Tables

#process_dependents, #process_table, #process_tables

Methods included from Schemas::Enums

#process_enum, #process_enums

Methods included from Schemas::Functions

#process_function, #process_functions

Methods included from Schemas

#process_schema

Methods included from Extensions

#process_extension

Constructor Details

#initialize(database, differences) ⇒ ToMigrations

Returns a new instance of ToMigrations.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dynamic_migrations/postgres/server/database/differences/to_migrations.rb', line 28

def initialize database, differences
  @logger = Logging.logger[self]

  raise UnexpectedDatabaseObjectError, database unless database.is_a? Database
  @database = database

  raise UnexpectedDifferencesObjectError, differences unless differences.is_a? Differences
  @differences = differences

  # the generator which will build the migrations
  @generator = Generator.new
end

Instance Method Details

#migrationsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dynamic_migrations/postgres/server/database/differences/to_migrations.rb', line 41

def migrations
  # process all the extensions
  log.debug "Processing Extensions"
  extension_names = differences[:configuration][:extensions].keys
  extension_names.each do |extension_name|
    log.debug "Processing Extension `#{extension_name}`"
    process_extension extension_name, differences[:configuration][:extensions][extension_name], differences[:database][:extensions][extension_name]
  end

  # process all the schemas (we can fetch the schema names from either the
  # configuration or the database object)
  log.debug "Processing Schemas"
  schema_names = differences[:configuration][:schemas].keys
  schema_names.each do |schema_name|
    log.debug "Processing Schema `#{schema_name}`"
    process_schema schema_name, differences[:configuration][:schemas][schema_name], differences[:database][:schemas][schema_name]
  end

  # return the migrations (they are sorted via a dependency algorithm)
  @generator.migrations
end