talentbox-sequel-rails 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- talentbox-sequel-rails (0.3.5)
5
- rails (~> 3.2.0)
4
+ talentbox-sequel-rails (0.3.6)
5
+ railties (~> 3.2.0)
6
6
  sequel (~> 3.28)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
11
  ZenTest (4.6.2)
12
- actionmailer (3.2.8)
13
- actionpack (= 3.2.8)
14
- mail (~> 2.4.4)
15
12
  actionpack (3.2.8)
16
13
  activemodel (= 3.2.8)
17
14
  activesupport (= 3.2.8)
@@ -25,18 +22,9 @@ GEM
25
22
  activemodel (3.2.8)
26
23
  activesupport (= 3.2.8)
27
24
  builder (~> 3.0.0)
28
- activerecord (3.2.8)
29
- activemodel (= 3.2.8)
30
- activesupport (= 3.2.8)
31
- arel (~> 3.0.2)
32
- tzinfo (~> 0.3.29)
33
- activeresource (3.2.8)
34
- activemodel (= 3.2.8)
35
- activesupport (= 3.2.8)
36
25
  activesupport (3.2.8)
37
26
  i18n (~> 0.6)
38
27
  multi_json (~> 1.0)
39
- arel (3.0.2)
40
28
  autotest (4.4.6)
41
29
  ZenTest (>= 4.4.1)
42
30
  builder (3.0.4)
@@ -46,13 +34,7 @@ GEM
46
34
  i18n (0.6.1)
47
35
  journey (1.0.4)
48
36
  json (1.7.5)
49
- mail (2.4.4)
50
- i18n (>= 0.4.0)
51
- mime-types (~> 1.16)
52
- treetop (~> 1.4.8)
53
- mime-types (1.19)
54
37
  multi_json (1.3.6)
55
- polyglot (0.3.3)
56
38
  rack (1.4.1)
57
39
  rack-cache (1.2)
58
40
  rack (>= 0.4)
@@ -60,14 +42,6 @@ GEM
60
42
  rack
61
43
  rack-test (0.6.2)
62
44
  rack (>= 1.0)
63
- rails (3.2.8)
64
- actionmailer (= 3.2.8)
65
- actionpack (= 3.2.8)
66
- activerecord (= 3.2.8)
67
- activeresource (= 3.2.8)
68
- activesupport (= 3.2.8)
69
- bundler (~> 1.0)
70
- railties (= 3.2.8)
71
45
  railties (3.2.8)
72
46
  actionpack (= 3.2.8)
73
47
  activesupport (= 3.2.8)
@@ -94,10 +68,6 @@ GEM
94
68
  tilt (~> 1.1, != 1.3.0)
95
69
  thor (0.16.0)
96
70
  tilt (1.3.3)
97
- treetop (1.4.11)
98
- polyglot
99
- polyglot (>= 0.3.1)
100
- tzinfo (0.3.33)
101
71
  yard (0.7.3)
102
72
 
103
73
  PLATFORMS
data/History.md CHANGED
@@ -1,6 +1,25 @@
1
- 0.3.6 - dev
1
+ 0.3.7 - dev
2
2
  ===========
3
3
 
4
+ 0.3.6
5
+ =====
6
+
7
+ * Ensure some tasks use the right db after setting `Rails.env`:
8
+ - `db:schema:load`
9
+ - `db:schema:dump`
10
+ - `db:force_close_open_connections`
11
+ * Add check for pending migrations before running task depending on schema:
12
+ - `db:schema:load`
13
+ - `db:test:prepare`
14
+ * Make database task more like what rails is doing:
15
+ - `db:load` do not create the db anymore
16
+ - `db:create` don't create the test db automatically
17
+ - `db:drop` don't drop the test db automatically
18
+ - `db:test:prepare` don't depend on `db:reset` which was loading `db:seed` (Sean Kirby)
19
+ * Make `rake db:setup` load schema instead of running migrations (Markus Fenske)
20
+ * Depends on `railties` instead of `rails` to not pull `active_record`
21
+ as dependency (Markus Fenske)
22
+
4
23
  0.3.5
5
24
  =====
6
25
 
@@ -3,28 +3,23 @@ require 'sequel/extensions/migration'
3
3
  module Rails
4
4
  module Sequel
5
5
  class Migrations
6
-
7
6
  class << self
8
-
9
7
  def migrate_up!(version=nil)
10
8
  opts = {}
11
9
  opts[:target] = version.to_i if version
12
-
13
-
14
-
15
10
  ::Sequel::Migrator.run(::Sequel::Model.db, "db/migrate", opts)
16
11
  end
17
12
 
18
13
  def migrate_down!(version=nil)
19
14
  opts = {}
20
15
  opts[:target] = version.to_i if version
21
-
22
16
  ::Sequel::Migrator.run(::Sequel::Model.db, "db/migrate", opts)
23
17
  end
24
-
18
+
19
+ def pending_migrations?
20
+ !::Sequel::Migrator.is_current?(::Sequel::Model.db, "db/migrate")
21
+ end
25
22
  end
26
-
27
-
28
23
  end
29
24
  end
30
25
  end
@@ -1,25 +1,38 @@
1
1
  # TODO: DRY these up
2
2
  namespace :db do
3
+ def db_for_current_env
4
+ @db_for_current_env ||= {}
5
+ @db_for_current_env[Rails.env] ||= begin
6
+ config = ::Rails::Sequel.configuration.environment_for(Rails.env)
7
+ Sequel.connect(config)
8
+ end
9
+ end
10
+
11
+ # desc "Raises an error if there are pending migrations"
12
+ task :abort_if_pending_migrations => [:environment, "db:migrate:load"] do
13
+ if Rails::Sequel::Migrations.pending_migrations?
14
+ puts "You have pending migrations:"
15
+ abort %{Run `rake db:migrate` to update your database then try again.}
16
+ end
17
+ end
18
+
3
19
  namespace :schema do
4
20
  desc "Create a db/schema.rb file that can be portably used against any DB supported by Sequel"
5
21
  task :dump => :environment do
6
22
  Sequel.extension :schema_dumper
7
- db = Sequel.connect(::Rails::Sequel.configuration.environment_for(Rails.env))
8
23
  File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file|
9
- file.write db.dump_schema_migration(same_db: true)
24
+ file.write db_for_current_env.dump_schema_migration(same_db: true)
10
25
  end
11
26
  Rake::Task["db:schema:dump"].reenable
12
27
  end
13
-
28
+
14
29
  desc "Load a schema.rb file into the database"
15
30
  task :load => :environment do
16
- require 'sequel-rails/storage'
17
- Rails::Sequel::Storage.new(Rails.env).create
18
-
19
31
  file = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
20
32
  if File.exists?(file)
33
+ require 'sequel/extensions/migration'
21
34
  load(file)
22
- Sequel::Migration.descendants.first.apply(::Sequel::Model.db, :up)
35
+ Sequel::Migration.descendants.first.apply(db_for_current_env, :up)
23
36
  else
24
37
  abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/boot.rb to limit the frameworks that will be loaded}
25
38
  end
@@ -34,18 +47,14 @@ namespace :db do
34
47
  end
35
48
  end
36
49
 
37
- desc "Create the database defined in config/database.yml for the current Rails.env - also creates the test database if Rails.env.development?"
50
+ desc "Create the database defined in config/database.yml for the current Rails.env"
38
51
  task :create, [:env] => :environment do |t, args|
39
52
  args.with_defaults(:env => Rails.env)
40
-
53
+
41
54
  require 'sequel-rails/storage'
42
55
  Rails::Sequel::Storage.new(args.env).create
43
-
44
- if Rails.env.development? && Rails.configuration.database_configuration['test']
45
- Rails::Sequel::Storage.new('test').create
46
- end
47
56
  end
48
-
57
+
49
58
  namespace :drop do
50
59
  desc 'Drops all the local databases defined in config/database.yml'
51
60
  task :all => :environment do
@@ -53,17 +62,13 @@ namespace :db do
53
62
  Rails::Sequel::Storage.drop_all
54
63
  end
55
64
  end
56
-
57
- desc "Create the database defined in config/database.yml for the current Rails.env - also creates the test database if Rails.env.development?"
65
+
66
+ desc "Create the database defined in config/database.yml for the current Rails.env"
58
67
  task :drop, [:env] => :environment do |t, args|
59
68
  args.with_defaults(:env => Rails.env)
60
-
69
+
61
70
  require 'sequel-rails/storage'
62
71
  Rails::Sequel::Storage.new(args.env).drop
63
-
64
- if Rails.env.development? && Rails.configuration.database_configuration['test']
65
- Rails::Sequel::Storage.new('test').drop
66
- end
67
72
  end
68
73
 
69
74
  namespace :migrate do
@@ -102,62 +107,63 @@ namespace :db do
102
107
  Rake::Task["db:schema:dump"].invoke if Rails.env != 'test'
103
108
  end
104
109
  end
105
-
110
+
106
111
  desc 'Migrate the database to the latest version'
107
- task :migrate => :'migrate:load' do
112
+ task :migrate => "migrate:load" do
108
113
  Rails::Sequel::Migrations.migrate_up!(ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
109
114
  Rake::Task["db:schema:dump"].invoke if Rails.env != 'test'
110
115
  end
111
116
 
112
117
  desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
113
- task :rollback => :'migrate:load' do
118
+ task :rollback => "migrate:load" do
114
119
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
115
120
  Sequel::Migrator.rollback('db/migrate/', step)
116
121
  Rake::Task["db:schema:dump"].invoke if Rails.env != 'test'
117
122
  end
118
123
 
119
124
  desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
120
- task :forward => :'migrate:load' do
125
+ task :forward => "migrate:load" do
121
126
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
122
127
  Sequel::Migrator.forward('db/migrate/', step)
123
128
  Rake::Task["db:schema:dump"].invoke if Rails.env != 'test'
124
129
  end
125
-
130
+
126
131
  desc 'Load the seed data from db/seeds.rb'
127
- task :seed => :environment do
132
+ task :seed => :abort_if_pending_migrations do
128
133
  seed_file = File.join(Rails.root, 'db', 'seeds.rb')
129
134
  load(seed_file) if File.exist?(seed_file)
130
135
  end
131
-
136
+
132
137
  desc 'Create the database, load the schema, and initialize with the seed data'
133
- task :setup => [ 'db:create', 'db:migrate', 'db:seed' ]
134
-
138
+ task :setup => [ 'db:create', 'db:schema:load', 'db:seed' ]
139
+
135
140
  desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
136
141
  task :reset => [ 'db:drop', 'db:setup' ]
137
-
142
+
138
143
  desc 'Forcibly close any open connections to the test database'
139
144
  task :force_close_open_connections => :environment do
140
145
  if Rails.env.test?
141
- db_config = Rails.configuration.database_configuration[Rails.env].symbolize_keys
142
- begin
143
- #Will only work on Postgres > 8.4
144
- Sequel::Model.db.execute <<-SQL.gsub(/^\s{9}/,'')
145
- SELECT COUNT(pg_terminate_backend(procpid))
146
- FROM pg_stat_activity
147
- WHERE datname = '#{db_config[:database]}';
148
- SQL
149
- rescue => e
150
- #Will raise an error as it kills existing process running this command
151
- #Seems to be only way to ensure *all* test connections are closed
152
- end
153
- end
146
+ begin
147
+ #Will only work on Postgres > 8.4
148
+ db_for_current_env.execute <<-SQL.gsub(/^\s{9}/,'')
149
+ SELECT COUNT(pg_terminate_backend(procpid))
150
+ FROM pg_stat_activity
151
+ WHERE datname = '#{db_config[:database]}';
152
+ SQL
153
+ rescue => e
154
+ #Will raise an error as it kills existing process running this command
155
+ #Seems to be only way to ensure *all* test connections are closed
156
+ end
157
+ end
154
158
  end
155
-
159
+
156
160
  namespace :test do
157
- task :prepare do
161
+ task :prepare => "db:abort_if_pending_migrations" do
158
162
  Rails.env = 'test'
159
- Rake::Task['db:force_close_open_connections'].invoke()
160
- Rake::Task['db:reset'].invoke()
163
+ Rake::Task['db:force_close_open_connections'].invoke
164
+ Rake::Task['db:drop'].invoke
165
+ Rake::Task['db:create'].invoke
166
+ Rake::Task['db:schema:load'].invoke
161
167
  Sequel::DATABASES.each do |db|
162
168
  db.disconnect
163
169
  end
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Sequel
3
- VERSION = "0.3.5"
3
+ VERSION = "0.3.6"
4
4
  end
5
5
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
20
20
  s.rdoc_options = ["--charset=UTF-8"]
21
21
  s.add_runtime_dependency("sequel", ["~> 3.28"])
22
- s.add_runtime_dependency("rails", ["~> 3.2.0"])
22
+ s.add_runtime_dependency("railties", ["~> 3.2.0"])
23
23
 
24
24
  s.add_development_dependency("rake", ["~> 0.8.7"])
25
25
  s.add_development_dependency("yard", ["~> 0.5"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talentbox-sequel-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -29,7 +29,7 @@ dependencies:
29
29
  - !ruby/object:Gem::Version
30
30
  version: '3.28'
31
31
  - !ruby/object:Gem::Dependency
32
- name: rails
32
+ name: railties
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  none: false
35
35
  requirements:
@@ -191,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
191
  version: '0'
192
192
  segments:
193
193
  - 0
194
- hash: -3701803564310894851
194
+ hash: 3233115191167619795
195
195
  required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  none: false
197
197
  requirements:
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  segments:
202
202
  - 0
203
- hash: -3701803564310894851
203
+ hash: 3233115191167619795
204
204
  requirements: []
205
205
  rubyforge_project:
206
206
  rubygems_version: 1.8.24