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
- migrate_names = apply_files.collect {|path| File.basename(path).partition('_apply').first}
98
- # NOTE: could package these up into one insert, but it is very small, and will have very few migrates, so not a big deal
99
- migrate_names.each do |name|
100
- dbh.query("INSERT INTO migrate SET migrated_at = NOW(), name = #{name.to_sql}")
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, 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
- load_sql(apply_filename(migrate_name))
28
- Doh.db.query("INSERT INTO #@table SET migrated_at = NOW(), name = #{migrate_name.to_sql}")
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]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dohmysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: