db_version_manager 0.0.1
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/README.rdoc +56 -0
- data/Rakefile.rb +65 -0
- data/config/database.yml +5 -0
- data/config/initializer.rb +5 -0
- metadata +94 -0
data/README.rdoc
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
== Installation
|
2
|
+
|
3
|
+
sudo apt-get install ruby1.9.1-full ruby1.9.1-dev postgresql libpq-dev
|
4
|
+
sudo gem install pg activerecord-pg-adapter
|
5
|
+
sudo gem install db_version_manager
|
6
|
+
|
7
|
+
|
8
|
+
== Configuration
|
9
|
+
|
10
|
+
Configure DB settings in `config/database.yml`, if needed, change `config/initializer.rb`
|
11
|
+
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
Available tasks are:
|
16
|
+
rake db:migrate[version] # Migrates DB to specified version (if no argument given, updates to latest migration).
|
17
|
+
rake db:version # Show current DB version.
|
18
|
+
rake help # Help
|
19
|
+
rake migration:applied # Show migrations that are applied.
|
20
|
+
rake migration:generate[description] # Generate new migration.
|
21
|
+
rake migration:unapplied # Show migrations that are not applied.
|
22
|
+
rake migration:version # Show current latest migration version.
|
23
|
+
|
24
|
+
|
25
|
+
== Example scenario
|
26
|
+
|
27
|
+
TODO-s:
|
28
|
+
* If you have Gems bin in your path, you can also just run ./db_version_manager
|
29
|
+
* Without cloning but with just Gem installation (see first)
|
30
|
+
|
31
|
+
=== Obtain db_version-manager
|
32
|
+
|
33
|
+
git clone https://github.com/tione/db_version_manager.git
|
34
|
+
cd db_version_manager
|
35
|
+
|
36
|
+
|
37
|
+
=== Configure database
|
38
|
+
|
39
|
+
config/database.yml
|
40
|
+
|
41
|
+
|
42
|
+
=== Generate migration template what to edit
|
43
|
+
|
44
|
+
rake migration:generate["This is my migration description"]
|
45
|
+
|
46
|
+
|
47
|
+
=== Edit your template in ./app/migrate/date_name.rb
|
48
|
+
|
49
|
+
1. For up() define for example "CREATE TABLE .."
|
50
|
+
2. For down() define for example "DROP TABLE .."
|
51
|
+
|
52
|
+
=== Migrate changes to DB
|
53
|
+
|
54
|
+
rake db:migrate # if no version given, to last is migrated. you can also downgrade so.
|
55
|
+
|
56
|
+
|
data/Rakefile.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
load_path = "."
|
2
|
+
$:.unshift(load_path) unless $:.include?(load_path)
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
require 'active_record'
|
6
|
+
require 'config/initializer.rb'
|
7
|
+
|
8
|
+
desc "Generate new migration."
|
9
|
+
task 'migration:generate', [:description] do |t, args|
|
10
|
+
desc = args.description or raise ArgumentError.new "You have to specify *description* for migration."
|
11
|
+
time = Time.new
|
12
|
+
version = "#{time.year}#{time.month}#{time.day}#{time.hour}#{time.min}#{time.sec}"
|
13
|
+
words = desc.split(/[^\w]/).select {|c| c!=""}
|
14
|
+
words << version
|
15
|
+
klass = words.collect{|w| w.capitalize}.join("")
|
16
|
+
name = words.join("_")
|
17
|
+
file_name = "db/migrate/#{version}_#{name}.rb"
|
18
|
+
contents = "
|
19
|
+
class #{klass} < ActiveRecord::Migration
|
20
|
+
def up
|
21
|
+
execute 'SQL here'
|
22
|
+
end
|
23
|
+
|
24
|
+
def down
|
25
|
+
execute 'SQL here'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
"
|
29
|
+
File.open(file_name, 'w+') do |file|
|
30
|
+
file.write(contents)
|
31
|
+
end
|
32
|
+
puts "Created file #{file_name}, please see also: http://api.rubyonrails.org/classes/ActiveRecord/Migration.html"
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Show current latest migration version."
|
36
|
+
task 'migration:version' do
|
37
|
+
puts ActiveRecord::Migrator.current_migration
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Show migrations that are not applied."
|
41
|
+
task 'migration:unapplied' do
|
42
|
+
puts ActiveRecord::Migrator.pending_migrations
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Show migrations that are applied."
|
46
|
+
task 'migration:applied' do
|
47
|
+
puts ActiveRecord::Migrator.applied
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "Show current DB version."
|
51
|
+
task 'db:version' do
|
52
|
+
puts ActiveRecord::Migrator.current_version
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Migrates DB to specified version (if no argument given, updates to latest migration)."
|
56
|
+
task 'db:migrate', [:version] do |t, args|
|
57
|
+
ActiveRecord::Migrator.migrate('db/migrate', args.version.to_i ? args.version.to_i : nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "Help"
|
61
|
+
task :help do
|
62
|
+
puts "Available tasks are:\n"
|
63
|
+
puts `rake --tasks`
|
64
|
+
end
|
65
|
+
task :default => :help
|
data/config/database.yml
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: db_version_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Margus P\xC3\xA4rt"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-01-20 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: active_record
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
description: Uses Rake and ActiveRecord::Migration.
|
47
|
+
email: margus@tione.eu
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files: []
|
53
|
+
|
54
|
+
files:
|
55
|
+
- README.rdoc
|
56
|
+
- Rakefile.rb
|
57
|
+
- config/initializer.rb
|
58
|
+
- config/database.yml
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: https://github.com/tione/anchor
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 9
|
76
|
+
- 2
|
77
|
+
version: 1.9.2
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Simple way to keep track of your DB changes. Can be used with MySQL, Postgre, Oracle etc :)
|
93
|
+
test_files: []
|
94
|
+
|