rails_structure_loading 0.1.0
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/LICENSE +20 -0
- data/README.rdoc +36 -0
- data/lib/rails_structure_loading.rb +2 -0
- data/lib/tasks/rails_structure_loading.rb +74 -0
- metadata +59 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Nick Gauthier
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
= rails_structure_loading
|
2
|
+
|
3
|
+
Rails structure loading patches rails tasks to allow you to
|
4
|
+
store and retrieve your database in SQL format.
|
5
|
+
|
6
|
+
Currently it only supports PostgreSQL
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
From gemcutter:
|
11
|
+
|
12
|
+
gem install rails_structure_loading
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
|
16
|
+
in your Rakefile:
|
17
|
+
|
18
|
+
require 'rails_structure_loading'
|
19
|
+
|
20
|
+
== What it does
|
21
|
+
|
22
|
+
=== New Tasks
|
23
|
+
|
24
|
+
* db:structure:load - loads db/structure.sql into the DB
|
25
|
+
* db:structure:dump - creates db/structure.sql from the DB
|
26
|
+
* db:domain:load - loads db/domain.sql into the DB (this is your app's domain data, not seed data)
|
27
|
+
* db:domain:dump - dumps the data in the database into db/domain.sql
|
28
|
+
|
29
|
+
=== Modified Tasks
|
30
|
+
|
31
|
+
* db:reset will load the structure and domain data if the file exists, otherwise it will use the schema as usual
|
32
|
+
* db:migrate will dump the structure and domain data after running
|
33
|
+
|
34
|
+
== Copyright
|
35
|
+
|
36
|
+
Copyright (c) 2009 Nick Gauthier. See LICENSE for details.
|
@@ -0,0 +1,74 @@
|
|
1
|
+
namespace :db do
|
2
|
+
def structure(prefix = "")
|
3
|
+
File.join(RAILS_ROOT, 'db', "#{prefix}structure.sql")
|
4
|
+
end
|
5
|
+
|
6
|
+
def domain
|
7
|
+
File.join(RAILS_ROOT, 'db', "domain.sql")
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :structure do
|
11
|
+
desc "Load the structure.sql file into the test database"
|
12
|
+
task :load => [:environment] do
|
13
|
+
if File.exists?(structure)
|
14
|
+
File.open(structure) do |f|
|
15
|
+
$stderr.write "** Loading structure from #{structure}\n"
|
16
|
+
ActiveRecord::Base.connection.execute(f.read)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
$stderr.write "** Structure file does not exist: #{structure}\n"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
task :dump do
|
24
|
+
FileUtils.cp structure("#{RAILS_ENV.downcase}_"), structure
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
namespace :domain do
|
29
|
+
desc "Load the domain.sql file into the current database"
|
30
|
+
task :load => [:environment] do
|
31
|
+
if File.exists?(domain)
|
32
|
+
File.open(domain) do |f|
|
33
|
+
$stderr.write "** Loading domain data from #{domain}\n"
|
34
|
+
ActiveRecord::Base.connection.execute(f.read)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
$stderr.write "** Domain file does not exist: #{domain}\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Dump the domain data to domain.sql"
|
42
|
+
task :dump do
|
43
|
+
conf = Rails::Configuration.new.database_configuration[RAILS_ENV]
|
44
|
+
raise "Don't know how to handle anything but postgres" unless conf["adapter"] == "postgresql"
|
45
|
+
$stderr.write "** Dumping domain data to #{domain}\n"
|
46
|
+
$stderr.write "** If your database has a password, you will have to enter it here\n"
|
47
|
+
opts = []
|
48
|
+
opts << "--data-only"
|
49
|
+
opts << "--column-inserts"
|
50
|
+
opts << "--exclude-table=schema_migrations"
|
51
|
+
opts << "-U #{conf["username"]}" if conf["username"]
|
52
|
+
opts = opts.join(" ")
|
53
|
+
`pg_dump #{opts} #{conf["database"]} > #{domain}`
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
namespace :db do
|
59
|
+
if File.exists?(structure)
|
60
|
+
# fully override db:reset
|
61
|
+
Rake.application.send(:eval, "@tasks.delete('db:reset')")
|
62
|
+
desc "Reset the database from the rails structure file corresponding to the environment"
|
63
|
+
task :reset => ['db:drop', 'db:create', 'db:structure:load', 'db:domain:load']
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Dump the structure after a migration"
|
67
|
+
task :migrate do
|
68
|
+
Rake::Task["db:structure:dump"].invoke if ActiveRecord::Base.schema_format == :sql
|
69
|
+
if RAILS_ENV == "test"
|
70
|
+
Rake::Task["db:domain:dump"].invoke if ActiveRecord::Base.schema_format == :sql
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_structure_loading
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Gauthier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-23 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Generate and load SQL structure files for your migrations
|
17
|
+
email: nick@smartlogicsolutions.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- README.rdoc
|
27
|
+
- lib/rails_structure_loading.rb
|
28
|
+
- lib/tasks/rails_structure_loading.rb
|
29
|
+
- LICENSE
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/ngauthier/rails_structure_loading
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --charset=UTF-8
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.3.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Generate and load SQL structure files for your migrations
|
58
|
+
test_files: []
|
59
|
+
|