Class: Prick::ReleaseMigration
Constant Summary
collapse
- FEATURES_TMPL_DIR =
"features"
- FILES =
[
FEATURES_SQL = "features.sql",
FEATURES_YML = "features.yml",
MIGRATIONS_SQL = "migrations.sql",
DIFF_SQL = "diff.sql"
]
Constants inherited
from Migration
Migration::KEEP_FILE
Instance Attribute Summary collapse
Attributes inherited from Migration
#path
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Migration
#<=>, #create, #destroy, #dump, #exist?, feature?, path, #prepare, #present?, #release_files, release_files, #to_s, version
Constructor Details
Returns a new instance of ReleaseMigration.
87
88
89
90
91
92
93
|
# File 'lib/prick/migration.rb', line 87
def initialize(path)
super(path, FEATURES_TMPL_DIR)
@features_yml = File.join(path, FEATURES_YML)
@features_sql = File.join(path, FEATURES_SQL)
@migrations_sql = File.join(path, MIGRATIONS_SQL)
@diff_sql = File.join(path, DIFF_SQL)
end
|
Instance Attribute Details
#diff_sql ⇒ Object
Returns the value of attribute diff_sql.
83
84
85
|
# File 'lib/prick/migration.rb', line 83
def diff_sql
@diff_sql
end
|
#features_sql ⇒ Object
Returns the value of attribute features_sql.
81
82
83
|
# File 'lib/prick/migration.rb', line 81
def features_sql
@features_sql
end
|
#features_yml ⇒ Object
Returns the value of attribute features_yml.
80
81
82
|
# File 'lib/prick/migration.rb', line 80
def features_yml
@features_yml
end
|
#migrations_sql ⇒ Object
Returns the value of attribute migrations_sql.
82
83
84
|
# File 'lib/prick/migration.rb', line 82
def migrations_sql
@migrations_sql
end
|
Class Method Details
.files(path) ⇒ Object
131
132
133
|
# File 'lib/prick/migration.rb', line 131
def self.files(path)
FILES.map { |file| File.join(path, file) }
end
|
Instance Method Details
#append_features_yml(paths, append: true) ⇒ Object
137
138
139
|
# File 'lib/prick/migration.rb', line 137
def append_features_yml(paths, append: true)
write_features_yml(read_features_yml.insert(append ? -1 : 0, *paths))
end
|
#feature_paths ⇒ Object
96
|
# File 'lib/prick/migration.rb', line 96
def feature_paths() read_features_yml end
|
#feature_versions ⇒ Object
95
|
# File 'lib/prick/migration.rb', line 95
def feature_versions() read_features_yml.map { |path| Migration.version(path) } end
|
#files ⇒ Object
85
|
# File 'lib/prick/migration.rb', line 85
def files() [features_yml, features_sql, migrations_sql, diff_sql] end
|
#include_feature(migration, append: true) ⇒ Object
‘feature` is a Feature object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/prick/migration.rb', line 99
def include_feature(migration, append: true)
migration.is_a?(FeatureMigration) or raise "Expected FeatureMigration object, got #{migration.class}"
!feature_paths.include?(migration.path) or raise Error, "Feature #{migration.version} is already included"
exclude_files = [Schema.data_file] +
migration.release_files +
migration.feature_paths.map { |path| FeatureMigration.release_files(path) }.flatten
Git.merge_branch(migration.version, exclude_files: exclude_files)
feature_paths = YAML.load(Git.read(migration.features_yml, branch: migration.version))
append_features_yml(feature_paths, append: append)
feature_paths.each { |feature_path|
if path != File.dirname(feature_path)
FileUtils.ln_s(File.join("../..", feature_path), path)
Git.add(File.join(path, File.basename(feature_path)))
end
}
end
|
#migrate(database_name) ⇒ Object
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/prick/migration.rb', line 119
def migrate(database_name)
puts "ReleaseMigration#migrate"
if File.exist?(migrations_sql)
Dir.chdir(path) {
puts " cd #{path}"
puts " psql -d #{database_name} < #{MIGRATIONS_SQL}"
Command.command "psql -d #{database_name} < #{MIGRATIONS_SQL}"
}
end
end
|
#read_features_yml(branch = nil) ⇒ Object
135
|
# File 'lib/prick/migration.rb', line 135
def read_features_yml(branch = nil) YAML.load(File.read(features_yml)) || [] end
|
#write_features_yml(paths) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/prick/migration.rb', line 141
def write_features_yml(paths)
FileUtils.cp(template_file(features_yml), features_yml)
File.open(features_yml, "a") { |f| f.write(paths.to_yaml) }
FileUtils.cp(template_file(features_sql), features_sql)
File.open(features_sql, "a") { |f|
paths.map { |path|
f.puts "\\cd #{File.basename(path)}"
f.puts "\\i migrate.sql" }
f.puts "\\cd .."
f.puts
}
Git.add(features_yml)
Git.add(features_sql)
end
|