vizzuality-sequel-rails 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,7 @@
1
1
  # TODO: DRY these up
2
+ ######################################################
3
+ # BEWARE: Regular Expressions of DOOOOOOOOOOOOOOOOOM #
4
+ ######################################################
2
5
  namespace :db do
3
6
  namespace :schema do
4
7
  desc "Create a db/schema.rb file that can be portably used against any DB supported by Sequel"
@@ -6,7 +9,25 @@ namespace :db do
6
9
  Sequel.extension :schema_dumper
7
10
  db = Sequel.connect(::Rails::Sequel.configuration.environment_for(Rails.env))
8
11
  File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file|
9
- file.write db.dump_schema_migration(same_db: true)
12
+ database = db.dump_schema_migration(same_db: true)
13
+ # 0. Add schema_migrations info (mucho importante!)
14
+ filenames = db[:schema_migrations].map{|x| x[:filename]}
15
+ statements = filenames.map do |f|
16
+ "self[:schema_migrations].insert(:filename => \"#{f}\")"
17
+ end
18
+
19
+ inserts = statements.map do |s|
20
+ " #{s}"
21
+ end.join("\n")
22
+
23
+ database.gsub!(/(create_table\(:schema_migrations\) do.+?end)/m, '\1'+"\n\n#{inserts}\n")
24
+
25
+ # 1. Fuck arbitrary whitespaces.
26
+ database.gsub!(/\s+$/,"\n")
27
+
28
+ # 2. Add new line at end of file
29
+ database += "\n"
30
+ file.write database
10
31
  end
11
32
  Rake::Task["db:schema:dump"].reenable
12
33
  end
@@ -19,6 +40,7 @@ namespace :db do
19
40
  file = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
20
41
  if File.exists?(file)
21
42
  load(file)
43
+ Sequel::Migration.descendants.first.apply(::Sequel::Model.db, :up)
22
44
  else
23
45
  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}
24
46
  end
@@ -129,7 +151,7 @@ namespace :db do
129
151
  end
130
152
 
131
153
  desc 'Create the database, load the schema, and initialize with the seed data'
132
- task :setup => [ 'db:create', 'db:migrate', 'db:seed' ]
154
+ task :setup => [ 'db:create', 'db:schema:load', 'db:seed' ]
133
155
 
134
156
  desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
135
157
  task :reset => [ 'db:drop', 'db:setup' ]
@@ -16,7 +16,6 @@ module Rails
16
16
 
17
17
  def self.setup(environment = nil)
18
18
  environment ||= Rails.env
19
- puts "[sequel-blat] Setting up the #{environment.inspect} environment:"
20
19
 
21
20
  @@connections ||= {}
22
21
  @@connections[environment] ||= ::Sequel.connect({:logger => configuration.logger}.merge(::Rails::Sequel.configuration.environment_for(environment.to_s)))
@@ -141,7 +141,7 @@ module Rails
141
141
  def execute(statement)
142
142
  commands = ["mysql"]
143
143
  commands << "--user" << username unless username.blank?
144
- commands << "--password" << password unless password.blank?
144
+ commands << "--password=#{password}" unless password.blank?
145
145
  commands << "--host" << host unless host.blank?
146
146
  commands << "-e" << statement
147
147
  system(*commands)
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Sequel
3
- VERSION = "0.3.4"
3
+ VERSION = "0.3.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vizzuality-sequel-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-03 00:00:00.000000000 Z
13
+ date: 2012-09-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sequel
@@ -205,4 +205,3 @@ test_files:
205
205
  - spec/rcov.opts
206
206
  - spec/spec.opts
207
207
  - spec/spec_helper.rb
208
- has_rdoc: