Module: DynamicMigrations::Postgres::Server::Database::ConfiguredSchemas

Included in:
DynamicMigrations::Postgres::Server::Database
Defined in:
lib/dynamic_migrations/postgres/server/database/configured_schemas.rb

Defined Under Namespace

Classes: ConfiguredSchemaAlreadyExistsError, ConfiguredSchemaDoesNotExistError

Instance Method Summary collapse

Instance Method Details

#add_configured_schema(schema_name) ⇒ Object

adds a new configured schema for this database



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dynamic_migrations/postgres/server/database/configured_schemas.rb', line 15

def add_configured_schema schema_name
  raise ExpectedSymbolError, schema_name unless schema_name.is_a? Symbol
  if has_configured_schema? schema_name
    raise(ConfiguredSchemaAlreadyExistsError, "Configured schema #{schema_name} already exists")
  end
  included_target = self
  if included_target.is_a? Database
    new_schema = @configured_schemas[schema_name] = Schema.new :configuration, included_target, schema_name
  else
    raise ModuleIncludedIntoUnexpectedTargetError, included_target
  end
  # sort the hash so that the schemas are in alphabetical order by name
  sorted_schemas = {}
  @configured_schemas.keys.sort.each do |schema_name|
    sorted_schemas[schema_name] = @configured_schemas[schema_name]
  end
  @configured_schemas = sorted_schemas
  # return the new schema
  new_schema
end

#configured_schema(schema_name) ⇒ Object

returns the configured schema object for the provided schema name, and raises an error if the schema does not exist



38
39
40
41
42
# File 'lib/dynamic_migrations/postgres/server/database/configured_schemas.rb', line 38

def configured_schema schema_name
  raise ExpectedSymbolError, schema_name unless schema_name.is_a? Symbol
  raise ConfiguredSchemaDoesNotExistError unless has_configured_schema? schema_name
  @configured_schemas[schema_name]
end

#configured_schemasObject

returns an array of this tables configured schemas



51
52
53
# File 'lib/dynamic_migrations/postgres/server/database/configured_schemas.rb', line 51

def configured_schemas
  @configured_schemas.values
end

#configured_schemas_hashObject

returns a hash of this tables configured schemas, keyed by schema name



56
57
58
# File 'lib/dynamic_migrations/postgres/server/database/configured_schemas.rb', line 56

def configured_schemas_hash
  @configured_schemas
end

#has_configured_schema?(schema_name) ⇒ Boolean

returns true if this table has a configured schema with the provided name, otherwise false

Returns:

  • (Boolean)

Raises:



45
46
47
48
# File 'lib/dynamic_migrations/postgres/server/database/configured_schemas.rb', line 45

def has_configured_schema? schema_name
  raise ExpectedSymbolError, schema_name unless schema_name.is_a? Symbol
  @configured_schemas.key? schema_name
end