xmigra 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6a51190444f9ed99043f444dbdf5167d64f1e2c
4
- data.tar.gz: 1a7a76612dee929f4f5ecf559d4cc5500fbdce50
3
+ metadata.gz: 841d32e7e4f11988348f7284060272f295f18e4d
4
+ data.tar.gz: 22dc8eeb6703aa74dc1587f13a7830e61216cec5
5
5
  SHA512:
6
- metadata.gz: e3c4014a0d8b55ee0029c10f1c2c9e8b673c17d7c2b7e931a4563b2cd8191186bdd2fcb08abc768bf1f2327f78594f6b23b032e2652cd0ec2cdd5e5b9445d37c
7
- data.tar.gz: 8aa634456ad0399ecbbf71540605a59bc942268fac69d4f9c9a3cf73b327b5633ec1306469d2d166dae2f8370c59b24adc56e84562d77909c7c40a3929fdbcd2
6
+ metadata.gz: d1ce7617249b3ec15d7bbad0ad673b15a7620df1f4d7966ce06e67fd15674e16e60b74539c56c89be88b2f559e9cb0c22d0fd812b0d573b91e3fdf2c71e1650d
7
+ data.tar.gz: e90c716f60ad4bd81c56e7af85c17f594aa6028a895ca91ad8c6dd65b53c044f342bfe12852f6ef555d8eb48e4c2c04f32b64853cac1f46482fd25c30bd82223
@@ -0,0 +1,44 @@
1
+
2
+ module XMigra
3
+ class AccessArtifact
4
+ def definition_sql
5
+ [
6
+ check_existence_sql(false, "%s existed before definition"),
7
+ creation_notice,
8
+ creation_sql + ";",
9
+ check_existence_sql(true, "%s was not created by definition"),
10
+ insert_access_creation_record_sql,
11
+ ].compact.join(ddl_block_separator)
12
+ end
13
+
14
+ attr_accessor :file_path, :filename_metavariable
15
+
16
+ def ddl_block_separator
17
+ "\n"
18
+ end
19
+
20
+ def check_existence_sql(for_existence, error_message)
21
+ nil
22
+ end
23
+
24
+ def creation_notice
25
+ nil
26
+ end
27
+
28
+ def creation_sql
29
+ if metavar = filename_metavariable
30
+ @definition.gsub(metavar) {|m| self.name}
31
+ else
32
+ @definition
33
+ end
34
+ end
35
+
36
+ def insert_access_creation_record_sql
37
+ nil
38
+ end
39
+
40
+ def printable_type
41
+ self.class.name.split('::').last.scan(/[A-Z]+[a-z]*/).collect {|p| p.downcase}.join(' ')
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,50 @@
1
+
2
+ require "tsort"
3
+
4
+ module XMigra
5
+ class AccessArtifactCollection
6
+ def initialize(path, options={})
7
+ @items = Hash.new
8
+ db_specifics = options[:db_specifics]
9
+ filename_metavariable = options[:filename_metavariable]
10
+ filename_metavariable = filename_metavariable.dup.freeze if filename_metavariable
11
+
12
+ XMigra.each_access_artifact(path) do |artifact|
13
+ @items[artifact.name] = artifact
14
+ artifact.extend(db_specifics) if db_specifics
15
+ artifact.filename_metavariable = filename_metavariable
16
+ end
17
+ end
18
+
19
+ def [](name)
20
+ @items[name]
21
+ end
22
+
23
+ def names
24
+ @items.keys
25
+ end
26
+
27
+ def at_path(fpath)
28
+ fpath = File.expand_path(fpath)
29
+ return find {|i| i.file_path == fpath}
30
+ end
31
+
32
+ def each(&block); @items.each_value(&block); end
33
+ alias tsort_each_node each
34
+
35
+ def tsort_each_child(node)
36
+ node.depends_on.each do |child|
37
+ yield @items[child]
38
+ end
39
+ end
40
+
41
+ include Enumerable
42
+ include TSort
43
+
44
+ def each_definition_sql
45
+ tsort_each do |artifact|
46
+ yield artifact.definition_sql
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,62 @@
1
+
2
+ require 'xmigra/migration'
3
+
4
+ module XMigra
5
+ class BranchUpgrade
6
+ TARGET_BRANCH = "resulting branch"
7
+ MIGRATION_COMPLETED = "completes migration to"
8
+
9
+ def initialize(path)
10
+ @file_path = path
11
+ @warnings = []
12
+
13
+ verinc_info = {}
14
+ if path.exist?
15
+ @found = true
16
+ begin
17
+ verinc_info = YAML.load_file(path)
18
+ rescue Error => e
19
+ warning "Failed to load branch upgrade migration (#{e.class}).\n #{e}"
20
+ verinc_info = {}
21
+ end
22
+ end
23
+
24
+ @base_migration = verinc_info[Migration::FOLLOWS]
25
+ @target_branch = (XMigra.secure_digest(verinc_info[TARGET_BRANCH]) if verinc_info.has_key? TARGET_BRANCH)
26
+ @migration_completed = verinc_info[MIGRATION_COMPLETED]
27
+ @sql = verinc_info['sql']
28
+ end
29
+
30
+ attr_reader :file_path, :base_migration, :target_branch, :migration_completed, :sql
31
+
32
+ def found?
33
+ @found
34
+ end
35
+
36
+ def applicable?(mig_chain)
37
+ return false if mig_chain.length < 1
38
+ return false unless (@base_migration && @target_branch)
39
+
40
+ return File.basename(mig_chain[-1].file_path) == XMigra.yaml_path(@base_migration)
41
+ end
42
+
43
+ def has_warnings?
44
+ not @warnings.empty?
45
+ end
46
+
47
+ def warnings
48
+ @warnings.dup
49
+ end
50
+
51
+ def migration_completed_id
52
+ Migration.id_from_filename(XMigra.yaml_path(migration_completed))
53
+ end
54
+
55
+ private
56
+
57
+ def warning(s)
58
+ s.freeze
59
+ @warnings << s
60
+ end
61
+ end
62
+ end