brant 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.textile +89 -0
- data/generators/brant_migration/brant_migration_generator.rb +53 -0
- data/generators/brant_migration/templates/migration.rb +7 -0
- data/lib/brant/migration.rb +18 -0
- data/lib/brant/migration_file.rb +68 -0
- data/lib/brant/tasks.rb +46 -0
- data/lib/brant.rb +28 -0
- data/lib/pkg/migrate/create_temp_file_20120206020466.rb +9 -0
- data/lib/pkg/migrate/edit_temp_file_20120213120974.rb +9 -0
- data/lib/pkg/migrate/maintain_temp_file_20120212430871.rb +9 -0
- metadata +154 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Denwen, Inc.
|
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.textile
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
h1. brant
|
2
|
+
|
3
|
+
Simple package migration management inspired from rails database migration management.
|
4
|
+
|
5
|
+
h2. Installation
|
6
|
+
|
7
|
+
<pre>
|
8
|
+
gem install brant
|
9
|
+
</pre>
|
10
|
+
|
11
|
+
In config/environment.rb add -
|
12
|
+
|
13
|
+
<pre>
|
14
|
+
gem.config('brant')
|
15
|
+
</pre>
|
16
|
+
|
17
|
+
In the Rakefile add -
|
18
|
+
|
19
|
+
<pre>
|
20
|
+
require 'brant'
|
21
|
+
require 'brant/tasks'
|
22
|
+
</pre>
|
23
|
+
|
24
|
+
h2. Usage
|
25
|
+
|
26
|
+
h3. Create a new migration
|
27
|
+
|
28
|
+
<pre>
|
29
|
+
script/generate brant_migration install_xml_package
|
30
|
+
</pre>
|
31
|
+
|
32
|
+
h3. Setup a new migration
|
33
|
+
|
34
|
+
<pre>
|
35
|
+
class InstallXmlPackage < Brant::Migration
|
36
|
+
def self.up
|
37
|
+
system("sudo apt-get install xml2")
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.down
|
41
|
+
system("sudo apt-get remove xml2")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
</pre>
|
45
|
+
|
46
|
+
h3. Load rails environment for custom tasks (optional)
|
47
|
+
|
48
|
+
<pre>
|
49
|
+
require 'config/environment'
|
50
|
+
|
51
|
+
class ProcessImages < Brant::Migration
|
52
|
+
def self.up
|
53
|
+
Image.last.process
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.down
|
57
|
+
Image.last.mark_as_unprocessed
|
58
|
+
end
|
59
|
+
end
|
60
|
+
</pre>
|
61
|
+
|
62
|
+
h3. Run pending migrations
|
63
|
+
|
64
|
+
<pre>
|
65
|
+
rake brant:migrate
|
66
|
+
</pre>
|
67
|
+
|
68
|
+
|
69
|
+
h3. Rollback last migration
|
70
|
+
|
71
|
+
<pre>
|
72
|
+
rake brant:rollback
|
73
|
+
</pre>
|
74
|
+
|
75
|
+
h2. Contributing to brant
|
76
|
+
|
77
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
78
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
79
|
+
* Fork the project.
|
80
|
+
* Start a feature/bugfix branch.
|
81
|
+
* Commit and push until you are happy with your contribution.
|
82
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
83
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
84
|
+
|
85
|
+
h2. Copyright
|
86
|
+
|
87
|
+
Copyright (c) 2012 Denwen, Inc. See LICENSE.txt for
|
88
|
+
further details.
|
89
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class BrantMigrationGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
# Perform validations on input
|
4
|
+
#
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
super
|
7
|
+
|
8
|
+
unless @args.present?
|
9
|
+
raise IOError, "Please include name of migration"
|
10
|
+
end
|
11
|
+
|
12
|
+
@name = @args.first
|
13
|
+
|
14
|
+
unless is_migration_unique?
|
15
|
+
raise IOError, "A migration titled #{@name} already exists"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Test if a migration with the given name already exists
|
20
|
+
#
|
21
|
+
def is_migration_unique?
|
22
|
+
!File.exists?(Brant.migrationsPath) ||
|
23
|
+
!Dir.entries(Brant.migrationsPath).
|
24
|
+
map{|f| f.split('_')[0..-2].join('_')}.
|
25
|
+
include?(@name)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Name of the migration file
|
29
|
+
#
|
30
|
+
def file_name
|
31
|
+
@file ||= @name + '_' +
|
32
|
+
Time.now.strftime("%Y%m%M%S") + ("%04d" % rand(1000)) +
|
33
|
+
'.rb'
|
34
|
+
end
|
35
|
+
|
36
|
+
# Name of the migration class within the new migration file
|
37
|
+
#
|
38
|
+
def class_name
|
39
|
+
@name.camelize
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Generate various files & directories
|
44
|
+
#
|
45
|
+
def manifest
|
46
|
+
record do |m|
|
47
|
+
m.directory Brant.rootPath
|
48
|
+
m.directory Brant.migrationsPath
|
49
|
+
m.template 'migration.rb',File.join(Brant.migrationsPath,file_name)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Brant
|
2
|
+
|
3
|
+
# Representation of the actual file that stores a migration
|
4
|
+
#
|
5
|
+
class MigrationFile
|
6
|
+
|
7
|
+
attr_accessor :filename, :klass, :timestamp
|
8
|
+
|
9
|
+
# Returns hash of migration file objects of all defnied migrations
|
10
|
+
# with their timestamps as the keys
|
11
|
+
#
|
12
|
+
def self.all
|
13
|
+
migrations = {}
|
14
|
+
|
15
|
+
if File.exists? Brant.migrationsPath
|
16
|
+
Dir.entries(Brant.migrationsPath).each do |file|
|
17
|
+
next if file.length < 3 || file.match(/^\./)
|
18
|
+
migration = new(file)
|
19
|
+
migrations[migration.timestamp] = migration
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
migrations
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns a hash of migration timestamps that
|
27
|
+
# have been performed
|
28
|
+
#
|
29
|
+
def self.existing
|
30
|
+
migrations = {}
|
31
|
+
|
32
|
+
if File.exists? Brant.migrationsConfigPath
|
33
|
+
File.open(Brant.migrationsConfigPath,'r') do |file|
|
34
|
+
while(line = file.gets)
|
35
|
+
migrations[line.chomp] = true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
migrations
|
41
|
+
end
|
42
|
+
|
43
|
+
# Update migrations config to show all finished migrations
|
44
|
+
#
|
45
|
+
def self.update(migrations)
|
46
|
+
File.open(Brant.migrationsConfigPath,'w') do |file|
|
47
|
+
file.write migrations.join("\n")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# Compare objects based on timestamp
|
53
|
+
#
|
54
|
+
def <=>(other)
|
55
|
+
self.timestamp <=> other.timestamp
|
56
|
+
end
|
57
|
+
|
58
|
+
# Constructor logic
|
59
|
+
#
|
60
|
+
def initialize(filename)
|
61
|
+
self.filename = filename
|
62
|
+
|
63
|
+
parts = self.filename.split('_')
|
64
|
+
self.timestamp = parts.last.split('.').first
|
65
|
+
self.klass = parts[0..-2].join('_').camelize
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/brant/tasks.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
namespace :brant do
|
3
|
+
|
4
|
+
desc "Run all pending migrations"
|
5
|
+
task :migrate do
|
6
|
+
existing_migrations = Brant::MigrationFile.existing
|
7
|
+
|
8
|
+
puts ""
|
9
|
+
|
10
|
+
Brant::MigrationFile.all.values.sort.each do |migration|
|
11
|
+
|
12
|
+
unless existing_migrations[migration.timestamp]
|
13
|
+
puts "Running migration " + migration.klass
|
14
|
+
|
15
|
+
require File.join(Brant.migrationsPath,migration.filename)
|
16
|
+
Object.const_get(migration.klass).send(:up)
|
17
|
+
|
18
|
+
existing_migrations[migration.timestamp] = true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Brant::MigrationFile.update(existing_migrations.keys.sort)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Undo the last migration"
|
26
|
+
task :rollback do
|
27
|
+
existing_migrations = Brant::MigrationFile.existing
|
28
|
+
all_migrations = Brant::MigrationFile.all
|
29
|
+
|
30
|
+
puts ""
|
31
|
+
|
32
|
+
if existing_migrations.length > 0
|
33
|
+
migration = all_migrations[existing_migrations.keys.sort.last]
|
34
|
+
|
35
|
+
puts "Rolling back migration " + migration.klass
|
36
|
+
|
37
|
+
require File.join(Brant.migrationsPath,migration.filename)
|
38
|
+
Object.const_get(migration.klass).send(:down)
|
39
|
+
|
40
|
+
existing_migrations.delete(migration.timestamp)
|
41
|
+
end
|
42
|
+
|
43
|
+
Brant::MigrationFile.update(existing_migrations.keys.sort)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/brant.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections.rb'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
require 'brant/migration'
|
5
|
+
require 'brant/migration_file'
|
6
|
+
|
7
|
+
|
8
|
+
module Brant
|
9
|
+
|
10
|
+
# Relative path of the root dir for packages
|
11
|
+
#
|
12
|
+
def self.rootPath
|
13
|
+
'pkg'
|
14
|
+
end
|
15
|
+
|
16
|
+
# Relative path of the dir that contains the migration files
|
17
|
+
#
|
18
|
+
def self.migrationsPath
|
19
|
+
File.join(rootPath,'migrate')
|
20
|
+
end
|
21
|
+
|
22
|
+
# Relative path of the hidden file that contains the current migration
|
23
|
+
#
|
24
|
+
def self.migrationsConfigPath
|
25
|
+
File.join(rootPath,'.migrations')
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Siddharth Batra
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-13 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activesupport
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
- 5
|
33
|
+
version: 2.3.5
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rdoc
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 31
|
45
|
+
segments:
|
46
|
+
- 3
|
47
|
+
- 12
|
48
|
+
version: "3.12"
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
requirement: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: bundler
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 59
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 0
|
63
|
+
- 22
|
64
|
+
version: 1.0.22
|
65
|
+
prerelease: false
|
66
|
+
type: :development
|
67
|
+
requirement: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: jeweler
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 49
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 8
|
79
|
+
- 3
|
80
|
+
version: 1.8.3
|
81
|
+
prerelease: false
|
82
|
+
type: :development
|
83
|
+
requirement: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rcov
|
86
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
prerelease: false
|
96
|
+
type: :development
|
97
|
+
requirement: *id005
|
98
|
+
description: Simple package migration management inspired from rails database migration management
|
99
|
+
email: siddharthabatra@gmail.com
|
100
|
+
executables: []
|
101
|
+
|
102
|
+
extensions: []
|
103
|
+
|
104
|
+
extra_rdoc_files:
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.textile
|
107
|
+
files:
|
108
|
+
- generators/brant_migration/brant_migration_generator.rb
|
109
|
+
- generators/brant_migration/templates/migration.rb
|
110
|
+
- lib/brant.rb
|
111
|
+
- lib/brant/migration.rb
|
112
|
+
- lib/brant/migration_file.rb
|
113
|
+
- lib/brant/tasks.rb
|
114
|
+
- lib/pkg/migrate/create_temp_file_20120206020466.rb
|
115
|
+
- lib/pkg/migrate/edit_temp_file_20120213120974.rb
|
116
|
+
- lib/pkg/migrate/maintain_temp_file_20120212430871.rb
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.textile
|
119
|
+
has_rdoc: true
|
120
|
+
homepage: http://github.com/denwen/brant
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 3
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
requirements: []
|
147
|
+
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 1.5.2
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: Simple package migrations by brant
|
153
|
+
test_files: []
|
154
|
+
|