21
22
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/enums.rb', line 21
def process_enum schema_name, enum_name, configuration_enum, database_enum
if configuration_enum[:exists] == true && !database_enum[:exists]
log.debug " Enum `#{enum_name}` exists in configuration but not in the database"
enum = @database.configured_schema(schema_name).enum(enum_name)
@generator.create_enum enum
if enum.has_description?
@generator. enum
end
elsif database_enum[:exists] == true && !configuration_enum[:exists]
log.debug " Enum `#{enum_name}` exists in database but not in the configuration"
enum = @database.loaded_schema(schema_name).enum(enum_name)
@generator.drop_enum enum
elsif configuration_enum[:values][:matches] == false
log.debug " Enum `#{enum_name}` exists in both configuration and the database"
log.debug " Enum `#{enum_name}` values are different"
original_enum = @database.loaded_schema(schema_name).enum(enum_name)
updated_enum = @database.configured_schema(schema_name).enum(enum_name)
@generator.update_enum original_enum, updated_enum
if configuration_enum[:description][:matches] == false
if configuration_enum[:description].nil?
log.debug " Enum `#{enum_name}` description exists in database but not in the configuration"
@generator. updated_enum
else
log.debug " Enum `#{enum_name}` description does not match"
@generator. updated_enum
end
end
elsif configuration_enum[:description][:matches] == false
enum = @database.configured_schema(schema_name).enum(enum_name)
if configuration_enum[:description].nil?
log.debug " Enum `#{enum_name}` description exists in database but not in the configuration"
@generator. enum
else
log.debug " Enum `#{enum_name}` description does not match"
@generator. enum
end
end
end
|