sequel_plus 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tasks/databases.rake +44 -31
- metadata +4 -4
data/lib/tasks/databases.rake
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
namespace :
|
1
|
+
namespace :sq do
|
2
2
|
task :SEQUEL_PLUS_APP_ROOT do
|
3
|
-
|
3
|
+
if defined? PADRINO_ROOT
|
4
|
+
SEQUEL_PLUS_APP_ROOT = PADRINO_ROOT
|
5
|
+
else
|
6
|
+
SEQUEL_PLUS_APP_ROOT = File.dirname File.expand_path Rake.application.rakefile
|
7
|
+
end
|
4
8
|
Rake::Task["environment"].invoke if Rake::Task.task_defined?("environment")
|
5
9
|
end
|
6
10
|
|
7
|
-
task :load_config =>
|
11
|
+
task :load_config => :SEQUEL_PLUS_APP_ROOT do
|
8
12
|
raise "no DB has been defined.\n Assign DB in your Rakefile or declare an :environment task and connect to your database." unless defined? DB
|
9
|
-
Sequel.extension :migration
|
10
|
-
Sequel.extension :schema_dumper
|
11
|
-
Sequel.extension :pretty_table
|
13
|
+
::Sequel.extension :migration
|
14
|
+
::Sequel.extension :schema_dumper
|
15
|
+
::Sequel.extension :pretty_table
|
12
16
|
end
|
13
17
|
|
14
18
|
desc "Displays a list of tables in the database"
|
@@ -18,10 +22,11 @@ namespace :db do
|
|
18
22
|
puts "#{'%3d' % (i+1)}: #{table_name}"
|
19
23
|
end
|
20
24
|
end
|
21
|
-
|
25
|
+
task :list_tables => :tables
|
26
|
+
|
22
27
|
desc "Displays content of table or lists all tables"
|
23
28
|
task :show, [:table] => :load_config do |t, args|
|
24
|
-
args.table ? DB[args.table.to_sym].print : Rake::Task["
|
29
|
+
args.table ? DB[args.table.to_sym].print : Rake::Task["sq:tables"].invoke
|
25
30
|
end
|
26
31
|
|
27
32
|
desc "Displays simple list of fields of table in sorted order"
|
@@ -33,18 +38,13 @@ namespace :db do
|
|
33
38
|
puts '=' * 80
|
34
39
|
end
|
35
40
|
|
36
|
-
desc "Displays a list of tables"
|
37
|
-
task :list_tables => :load_config do
|
38
|
-
DB.tables.sort{|a,b| a.to_s <=> b.to_s}.each_with_index{|table, i| puts ("%-2d" % (i + 1)) + table.to_s}
|
39
|
-
end
|
40
|
-
|
41
41
|
desc "Displays schema of table"
|
42
42
|
task :desc, [:table] => :load_config do |t, args|
|
43
43
|
def o(value, size = 25)
|
44
44
|
"%#{-1*size}s" % value.to_s
|
45
45
|
end
|
46
46
|
unless args[:table]
|
47
|
-
Rake::Task["
|
47
|
+
Rake::Task["sq:tables"].invoke
|
48
48
|
else
|
49
49
|
puts '==[' << args.table << ']' << '=' * (80 - args.table.size - 4)
|
50
50
|
DB.schema(args.table.to_sym).each_with_index do |col, i|
|
@@ -73,7 +73,7 @@ namespace :db do
|
|
73
73
|
desc "Dumps the schema to db/schema.db"
|
74
74
|
task :dump => [:load_config, :ensure_db_dir] do
|
75
75
|
schema = DB.dump_schema_migration
|
76
|
-
|
76
|
+
File.open(File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'schema.rb'), "w"){|f| f.write(schema)}
|
77
77
|
end
|
78
78
|
|
79
79
|
desc "drops the schema, using schema.rb"
|
@@ -84,51 +84,64 @@ namespace :db do
|
|
84
84
|
desc "loads the schema from db/schema.rb"
|
85
85
|
task :load => :load_config do
|
86
86
|
eval(File.read(File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'schema.rb'))).apply(DB, :up)
|
87
|
-
latest_version = Sequel::Migrator.latest_migration_version(File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'migrate'))
|
88
|
-
Sequel::Migrator.set_current_migration_version(DB, latest_version)
|
87
|
+
latest_version = ::Sequel::Migrator.latest_migration_version(File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'migrate'))
|
88
|
+
::Sequel::Migrator.set_current_migration_version(DB, latest_version)
|
89
89
|
puts "Database schema loaded version #{latest_version}"
|
90
90
|
end
|
91
91
|
|
92
92
|
desc "Returns current schema version"
|
93
93
|
task :version => :load_config do
|
94
|
-
puts "Current Schema Version: #{Sequel::Migrator.get_current_migration_version(DB)}"
|
94
|
+
puts "Current Schema Version: #{::Sequel::Migrator.get_current_migration_version(DB)}"
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking db:schema:dump."
|
99
99
|
task :migrate => :load_config do
|
100
|
-
Sequel::Migrator.apply(DB, File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'migrate'))
|
101
|
-
Rake::Task["
|
102
|
-
Rake::Task["
|
100
|
+
::Sequel::Migrator.apply(DB, File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'migrate'))
|
101
|
+
Rake::Task["sq:schema:dump"].invoke
|
102
|
+
Rake::Task["sq:schema:version"].invoke
|
103
103
|
end
|
104
104
|
|
105
105
|
namespace :migrate do
|
106
|
+
desc "Perform automigration (reset your db data)"
|
107
|
+
task :auto => :load_config do
|
108
|
+
::Sequel::Migrator.run DB, "db/migrate", :target => 0
|
109
|
+
::Sequel::Migrator.run DB, "db/migrate"
|
110
|
+
end
|
111
|
+
|
106
112
|
desc 'Rollbacks the database one migration and re-migrates up.'
|
107
113
|
task :redo => :load_config do
|
108
|
-
Rake::Task["
|
109
|
-
Rake::Task["
|
110
|
-
Rake::Task["
|
114
|
+
Rake::Task["sq:rollback"].invoke
|
115
|
+
Rake::Task["sq:migrate"].invoke
|
116
|
+
Rake::Task["sq:schema:dump"].invoke
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "Perform migration up/down to VERSION"
|
120
|
+
task :to, [:version] => :load_config do |t, args|
|
121
|
+
version = (args[:version] || ENV['VERSION']).to_s.strip
|
122
|
+
raise "No VERSION was provided" if version.empty?
|
123
|
+
::Sequel::Migrator.apply(DB, "db/migrate", version.to_i)
|
111
124
|
end
|
112
125
|
|
113
126
|
desc 'Runs the "up" for a given migration VERSION.'
|
114
127
|
task :up, [:version] => :load_config do |t, args|
|
115
|
-
raise "
|
128
|
+
raise "version is required" unless args[:version]
|
116
129
|
|
117
130
|
puts "migrating up to version #{args.version}"
|
118
|
-
Sequel::Migrator.apply(DB, File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'migrate'), args.version)
|
119
|
-
Rake::Task["
|
131
|
+
::Sequel::Migrator.apply(DB, File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'migrate'), args.version.to_i)
|
132
|
+
Rake::Task["sq:schema:dump"].invoke
|
120
133
|
end
|
121
134
|
|
122
135
|
desc 'Reverts to previous schema version. Specify the number of steps with STEP=n'
|
123
136
|
task :down, [:step] => :load_config do |t, args|
|
124
137
|
step = args[:step] ? args.step.to_i : 1
|
125
|
-
current_version = Sequel::Migrator.get_current_migration_version(DB)
|
138
|
+
current_version = ::Sequel::Migrator.get_current_migration_version(DB)
|
126
139
|
down_version = current_version - step
|
127
140
|
down_version = 0 if down_version < 0
|
128
141
|
|
129
142
|
puts "migrating down to version #{down_version}"
|
130
|
-
Sequel::Migrator.apply(DB, File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'migrate'), down_version)
|
131
|
-
Rake::Task["
|
143
|
+
::Sequel::Migrator.apply(DB, File.join(SEQUEL_PLUS_APP_ROOT, 'db', 'migrate'), down_version)
|
144
|
+
Rake::Task["sq:schema:dump"].invoke
|
132
145
|
end
|
133
146
|
|
134
147
|
desc "Creates a new migrate script. The verb is optional."
|
@@ -164,7 +177,7 @@ namespace :db do
|
|
164
177
|
|
165
178
|
desc 'Rolls the schema back to the previous version.'
|
166
179
|
task :rollback => :load_config do
|
167
|
-
Rake::Task["
|
180
|
+
Rake::Task["sq:migrate:down"].invoke
|
168
181
|
end
|
169
182
|
|
170
183
|
desc 'Drops all tables and recreates the schema from db/schema.rb'
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Lang
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-04 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|