Module: DbSchema
- Defined in:
- lib/db_schema.rb,
lib/db_schema/dsl.rb,
lib/db_schema/utils.rb,
lib/db_schema/reader.rb,
lib/db_schema/runner.rb,
lib/db_schema/changes.rb,
lib/db_schema/version.rb,
lib/db_schema/migrator.rb,
lib/db_schema/migration.rb,
lib/db_schema/validator.rb,
lib/db_schema/normalizer.rb,
lib/db_schema/operations.rb,
lib/db_schema/configuration.rb,
lib/db_schema/dsl/migration.rb
Defined Under Namespace
Modules: Changes, Operations, Reader, Utils, Validator
Classes: Configuration, DSL, InvalidSchemaError, Migration, Migrator, Normalizer, Runner, SchemaMismatch, UnsupportedOperation
Constant Summary
collapse
- VERSION =
'0.5'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.current_schema ⇒ Object
Returns the value of attribute current_schema.
21
22
23
|
# File 'lib/db_schema.rb', line 21
def current_schema
@current_schema
end
|
Class Method Details
.configuration ⇒ Object
69
70
71
|
# File 'lib/db_schema.rb', line 69
def configuration
@configuration ||= Configuration.new
end
|
50
51
52
|
# File 'lib/db_schema.rb', line 50
def configure(params)
@configuration = configuration.merge(params)
end
|
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/db_schema.rb', line 54
def configure_from_yaml(yaml_path, environment, **other_options)
data = Utils.symbolize_keys(YAML.load_file(yaml_path))
filtered_data = Utils.filter_by_keys(
data[environment.to_sym],
*%i(adapter host port database username password)
)
renamed_data = Utils.rename_keys(filtered_data, username: :user)
configure(renamed_data.merge(other_options))
end
|
.connection=(external_connection) ⇒ Object
65
66
67
|
# File 'lib/db_schema.rb', line 65
def connection=(external_connection)
@external_connection = external_connection
end
|
.describe(&block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/db_schema.rb', line 23
def describe(&block)
with_connection do |connection|
desired = DSL.new(block)
validate(desired.schema)
Normalizer.new(desired.schema, connection).normalize_tables
connection.transaction do
actual_schema = run_migrations(desired.migrations, connection)
changes = Changes.between(desired.schema, actual_schema)
log_changes(changes) if configuration.log_changes?
if configuration.dry_run?
raise Sequel::Rollback
else
@current_schema = desired.schema
return if changes.empty?
end
Runner.new(changes, connection).run!
if configuration.post_check_enabled?
perform_post_check(desired.schema, connection)
end
end
end
end
|
.reset! ⇒ Object
73
74
75
76
77
|
# File 'lib/db_schema.rb', line 73
def reset!
@external_connection = nil
@configuration = nil
@current_schema = nil
end
|