db_structure 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/db_structure.rb +14 -20
- metadata +2 -2
data/lib/db_structure.rb
CHANGED
@@ -33,27 +33,21 @@ module DBStructure
|
|
33
33
|
['production', 'test', 'development'].each do |target|
|
34
34
|
begin
|
35
35
|
ENV['RAILS_ENV'] = target
|
36
|
+
begin
|
37
|
+
puts "Recreating database #{config[target]['database']}"
|
38
|
+
ActiveRecord::Base.connection.execute("DROP DATABASE #{config[target]['database']}")
|
39
|
+
rescue
|
40
|
+
puts "Database #{config[target]['database']} doesn't exist yet"
|
41
|
+
ensure
|
42
|
+
ActiveRecord::Base.connection.execute("CREATE DATABASE #{config[target]['database']}")
|
43
|
+
ActiveRecord::Base.connection.execute("USE #{config[target]['database']}")
|
44
|
+
end
|
36
45
|
db_helper(config[target]['adapter']).split(/\s*;\s*/).each do |sql|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
ensure
|
43
|
-
ActiveRecord::Base.connection.execute("CREATE DATABASE #{config[target]['database']}")
|
44
|
-
ActiveRecord::Base.connection.execute("USE #{config[target]['database']}")
|
45
|
-
end
|
46
|
-
Dir['db/*.erbsql'].each do |filename|
|
47
|
-
File.open(filename, "r") do |file|
|
48
|
-
file.each_line do |line|
|
49
|
-
if line =~ /(create|CREATE).+?(table|TABLE).+?(\w+)/
|
50
|
-
begin
|
51
|
-
ActiveRecord::Base.connection.execute("DROP TABLE #{$3}")
|
52
|
-
rescue
|
53
|
-
puts "Table #{$3} does not exist"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
46
|
+
if sql =~ /(create|CREATE).+?(table|TABLE).+?(\w+)/
|
47
|
+
begin
|
48
|
+
ActiveRecord::Base.connection.execute("DROP TABLE #{$3}")
|
49
|
+
rescue
|
50
|
+
puts "Table #{$3} does not exist"
|
57
51
|
end
|
58
52
|
end
|
59
53
|
puts "Creating tables for #{config[target]['database']}..."
|
metadata
CHANGED