totem_activerecord 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +18 -16
- data/lib/totem_activerecord/shell_cmds/db.rb +81 -5
- data/lib/totem_activerecord/version.rb +1 -1
- data/totem_activerecord.gemspec +10 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9abc9ae52b8f85e580196c99dc30beafec21107
|
4
|
+
data.tar.gz: faa75b7ccec1ee289419180f9979a85cebc6f4fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0cdec374306571a3716d11e561ba33b65e0774410f4211c7fc895c7207660d9484a6c0f1a09dedf068e27511c0b47399d198e5e4c7bf2c08c499252ef92272b
|
7
|
+
data.tar.gz: 4b6b1a83df9dc637d174e9f930010227498fbe81798dfb8ed4315442b907832a174907384b926a4e9d3c81867565afeaaf9e262eb3abf00b8d9295c6083ca3b0
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# TotemActiverecord
|
2
2
|
|
3
|
-
This gem is
|
4
|
-
The version of the activerecord gem isn't locked down so that you can specify a specversion in your project's Gemfile.
|
3
|
+
This gem is the ActiveRecord add-on for [Totem](https://github.com/chadrem/totem).
|
5
4
|
|
6
5
|
## Installation
|
7
6
|
|
@@ -40,6 +39,13 @@ It is recommeended you do this so that your project is always in a known state:
|
|
40
39
|
|
41
40
|
gem 'activerecord', '3.2.17', :require => 'active_record'
|
42
41
|
|
42
|
+
You will also need to add the appropriate database specific gem to your Gemfile.
|
43
|
+
For the above example, you would add the following:
|
44
|
+
|
45
|
+
gem 'mysql2'
|
46
|
+
|
47
|
+
You should now run `bundle` again so it instals the new gems.
|
48
|
+
|
43
49
|
## Usage
|
44
50
|
|
45
51
|
Create your database:
|
@@ -58,25 +64,21 @@ Rollback your database (one migration back):
|
|
58
64
|
|
59
65
|
$ bundle exec totem db rollback
|
60
66
|
|
61
|
-
|
67
|
+
Create a new (empty) migration:
|
62
68
|
|
63
|
-
|
64
|
-
The filename and syntax is the same as what you would use in Rails.
|
69
|
+
$ bundle exec totem db migration <name>
|
65
70
|
|
66
|
-
|
71
|
+
Run the 'up' method for a given migration:
|
67
72
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
73
|
+
$ bundle exec totem db up <timestamp>
|
74
|
+
|
75
|
+
Run the 'down' method for a given migration:
|
76
|
+
|
77
|
+
$ bundle exec totem db down <timestamp>
|
76
78
|
|
77
79
|
## Models
|
78
80
|
|
79
|
-
You will need to manually create models in the `app` directory
|
81
|
+
You will need to manually create models in the `app` directory.
|
80
82
|
|
81
83
|
Example model `app/user.rb` to go with the above migration:
|
82
84
|
|
@@ -89,7 +91,7 @@ Rember to add the model to the `app/loader.rb` just like you do with all classes
|
|
89
91
|
|
90
92
|
## Contributing
|
91
93
|
|
92
|
-
1. Fork it
|
94
|
+
1. Fork it
|
93
95
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
94
96
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
95
97
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -3,10 +3,15 @@ module TotemActiverecord
|
|
3
3
|
class Db < Totem::ShellCmds::Base
|
4
4
|
def run
|
5
5
|
case @args[0]
|
6
|
-
when 'create'
|
7
|
-
when 'drop'
|
8
|
-
when 'migrate'
|
9
|
-
when 'rollback'
|
6
|
+
when 'create' then create
|
7
|
+
when 'drop' then drop
|
8
|
+
when 'migrate' then migrate
|
9
|
+
when 'rollback' then rollback
|
10
|
+
when 'migration' then migration(@args[1])
|
11
|
+
when 'up' then up(@args[1])
|
12
|
+
when 'down' then down(@args[1])
|
13
|
+
else
|
14
|
+
puts_usage
|
10
15
|
end
|
11
16
|
end
|
12
17
|
|
@@ -14,6 +19,7 @@ module TotemActiverecord
|
|
14
19
|
ActiveRecord::Base.establish_connection(TotemActiverecord.config.merge('database' => nil))
|
15
20
|
ActiveRecord::Base.connection.create_database(TotemActiverecord.config['database'])
|
16
21
|
ActiveRecord::Base.establish_connection(TotemActiverecord.config)
|
22
|
+
TotemActiverecord.reconnect
|
17
23
|
|
18
24
|
return true
|
19
25
|
end
|
@@ -27,7 +33,6 @@ module TotemActiverecord
|
|
27
33
|
def migrate
|
28
34
|
ActiveRecord::Migration.verbose = true
|
29
35
|
ActiveRecord::Migrator.migrate(TotemActiverecord.migrations_path)
|
30
|
-
|
31
36
|
TotemActiverecord.reconnect
|
32
37
|
|
33
38
|
return true
|
@@ -39,6 +44,77 @@ module TotemActiverecord
|
|
39
44
|
|
40
45
|
return true
|
41
46
|
end
|
47
|
+
|
48
|
+
def migration(name)
|
49
|
+
return false unless require_arg(name, :name)
|
50
|
+
|
51
|
+
name = name.gsub(/\s/,'_')
|
52
|
+
timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
53
|
+
filename = "#{timestamp}_#{name}.rb"
|
54
|
+
path = File.join(Totem.root, 'db', 'migrate', filename)
|
55
|
+
content = "class #{name.camelize} < ActiveRecord::Migration\nend"
|
56
|
+
|
57
|
+
puts "Creating migration: #{path}"
|
58
|
+
|
59
|
+
if File.exists?(path)
|
60
|
+
puts_error('Migration already exists.')
|
61
|
+
return false
|
62
|
+
end
|
63
|
+
|
64
|
+
File.open(path, 'w') { |f| f.write(content) }
|
65
|
+
|
66
|
+
return true
|
67
|
+
end
|
68
|
+
|
69
|
+
def up(timestamp)
|
70
|
+
return false unless require_arg(timestamp, :timestamp)
|
71
|
+
|
72
|
+
ActiveRecord::Migration.verbose = true
|
73
|
+
ActiveRecord::Migrator.up(TotemActiverecord.migrations_path, timestamp.to_i)
|
74
|
+
TotemActiverecord.reconnect
|
75
|
+
|
76
|
+
return true
|
77
|
+
end
|
78
|
+
|
79
|
+
def down(timestamp)
|
80
|
+
return false unless require_arg(timestamp, :timestamp)
|
81
|
+
|
82
|
+
ActiveRecord::Migration.verbose = true
|
83
|
+
ActiveRecord::Migrator.down(TotemActiverecord.migrations_path, timestamp.to_i)
|
84
|
+
TotemActiverecord.reconnect
|
85
|
+
|
86
|
+
return true
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def puts_usage
|
92
|
+
puts "Usage:\n bundle exec totem db <command>"
|
93
|
+
puts
|
94
|
+
puts "Commands:\n"
|
95
|
+
puts " create - Create the database if it doesn't exist."
|
96
|
+
puts " drop - Drop the database if it exists."
|
97
|
+
puts " migrate - Run all new migrations."
|
98
|
+
puts " rollback - Rollback one migration."
|
99
|
+
puts " migration <name> - Create a new migration with <name>."
|
100
|
+
puts " up <name> - Run 'up' method in the <name> migration."
|
101
|
+
puts " down <name> - Run 'down' method in the <name> migration."
|
102
|
+
end
|
103
|
+
|
104
|
+
def puts_error(message)
|
105
|
+
puts "ERROR: #{message}"
|
106
|
+
puts
|
107
|
+
puts_usage
|
108
|
+
end
|
109
|
+
|
110
|
+
def require_arg(val, name)
|
111
|
+
if val.nil? || val.length == 0
|
112
|
+
puts_error("You must provide a #{name}.")
|
113
|
+
return false
|
114
|
+
end
|
115
|
+
|
116
|
+
return true
|
117
|
+
end
|
42
118
|
end
|
43
119
|
end
|
44
120
|
end
|
data/totem_activerecord.gemspec
CHANGED
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'totem_activerecord/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'totem_activerecord'
|
8
8
|
spec.version = TotemActiverecord::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Chad Remesch']
|
10
|
+
spec.email = ['chad@remesch.com']
|
11
11
|
spec.summary = %q{ActiveRecord add-on for the Totem gem.}
|
12
12
|
spec.description = %q{Add an easy to use ORM to your Totem based applications.}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency(
|
22
|
-
spec.add_dependency(
|
21
|
+
spec.add_dependency('totem', '>= 0.0.5')
|
22
|
+
spec.add_dependency('activerecord')
|
23
23
|
|
24
|
-
spec.add_development_dependency(
|
25
|
-
spec.add_development_dependency(
|
24
|
+
spec.add_development_dependency('bundler', '~> 1.5')
|
25
|
+
spec.add_development_dependency('rake')
|
26
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: totem_activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Remesch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: totem
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.0.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.0.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|