dohmysql 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ require 'doh/mysql/file_util'
|
|
7
7
|
module DohDb
|
8
8
|
|
9
9
|
class DatabaseCreator
|
10
|
-
MIGRATE_TABLE_DEF = "CREATE TABLE migrate (migrated_at DATETIME NOT NULL, name CHAR(50) NOT NULL)"
|
10
|
+
MIGRATE_TABLE_DEF = "CREATE TABLE migrate (migrated_at DATETIME NOT NULL, name CHAR(50) NOT NULL, sql_applied TEXT NOT NULL)"
|
11
11
|
|
12
12
|
def initialize(sqlfiles_directory = nil, connector = nil)
|
13
13
|
@sqlfiles_directory = sqlfiles_directory || DohDb.sql_files_path
|
@@ -94,10 +94,10 @@ private
|
|
94
94
|
def apply_migrates(dbh, source_db)
|
95
95
|
apply_files = find_files("#{source_db}/migrate/*_apply.sql")
|
96
96
|
DohDb.load_sql(@connector.config, apply_files)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
dbh.query("INSERT INTO migrate SET migrated_at = NOW(), name = #{
|
97
|
+
apply_files.each do |path|
|
98
|
+
migrate_name = File.basename(path).slice(0..-11)
|
99
|
+
contents = File.open(path) {|file| file.read}
|
100
|
+
dbh.query("INSERT INTO migrate SET migrated_at = NOW(), name = #{migrate_name.to_sql}, sql_applied = #{contents.to_sql}")
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -16,7 +16,7 @@ class MigrateAnalyzer
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def check(migrate_name)
|
19
|
-
DohDb::DatabaseCreator.new.create_database_copy(CHECK_DATABASE, @database, true,
|
19
|
+
DohDb::DatabaseCreator.new.create_database_copy(CHECK_DATABASE, @database, true, false)
|
20
20
|
dump_sql(@sql_original)
|
21
21
|
|
22
22
|
runner = DohDb::MigrateRunner.new(@database)
|
@@ -24,8 +24,10 @@ class MigrateRunner
|
|
24
24
|
if migrate_exist?(migrate_name)
|
25
25
|
return [false, "migration #{migrate_name} has already been applied"]
|
26
26
|
end
|
27
|
-
|
28
|
-
|
27
|
+
fname = apply_filename(migrate_name)
|
28
|
+
load_sql(fname)
|
29
|
+
contents = File.open(fname) {|file| file.read}
|
30
|
+
Doh.db.query("INSERT INTO #@table SET migrated_at = NOW(), name = #{migrate_name.to_sql}, sql_applied = #{contents.to_sql}")
|
29
31
|
[true, "migration #{migrate_name} applied successfully"]
|
30
32
|
rescue Exception => excpt
|
31
33
|
[false, excpt.message]
|