padrino-gen 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -16
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/padrino-gen +8 -10
- data/lib/padrino-gen/generators/components/actions.rb +4 -4
- data/lib/padrino-gen/generators/model.rb +2 -1
- data/lib/padrino-gen/generators.rb +36 -0
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +325 -0
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +76 -8
- data/lib/padrino-gen.rb +1 -7
- data/padrino-gen.gemspec +5 -5
- data/test/helper.rb +10 -0
- metadata +3 -3
- data/lib/padrino-gen/generators/base.rb +0 -22
data/README.rdoc
CHANGED
@@ -1,15 +1,6 @@
|
|
1
|
-
= padrino-gen
|
1
|
+
= Agnostic Application Generators (padrino-gen)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
To install the 'full-stack' padrino framework, simply grab the latest version from gemcutter:
|
6
|
-
|
7
|
-
$ sudo gem install padrino --source http://gemcutter.org
|
8
|
-
|
9
|
-
This will install the necessary padrino gems to get you started.
|
10
|
-
Now you are ready to use this gem to enhance your existing Sinatra projects or build new Padrino applications.
|
11
|
-
|
12
|
-
== Overview
|
3
|
+
=== Overview
|
13
4
|
|
14
5
|
Padrino comes preloaded with flexible code generators powered in part by the excellent Thor gem
|
15
6
|
(incidentally also used in the Rails 3 generators). These generators are intended to allow for easy code generation
|
@@ -18,7 +9,7 @@ as possible, supporting a myriad of test frameworks, js libraries, mocking libra
|
|
18
9
|
|
19
10
|
See the wiki article for additional information: <...WIKI...>
|
20
11
|
|
21
|
-
=== Application Generator
|
12
|
+
=== Application Generator
|
22
13
|
|
23
14
|
Padrino provides generator support for quickly creating new Padrino applications. This provides many benefits
|
24
15
|
such as constructing the recommended Padrino application structure, auto-generating a Gemfile listing
|
@@ -78,7 +69,7 @@ This would be achieved through forking our project and reading through the code
|
|
78
69
|
the setup instructions inside the relevant files within <tt>lib/generators/components/</tt>. We are happy to accept pull requests
|
79
70
|
for additional component types not originally included (although helping us maintain them would also be appreciated).
|
80
71
|
|
81
|
-
=== Model Generator
|
72
|
+
=== Model Generator
|
82
73
|
|
83
74
|
Padrino provides generator support for quickly creating new models within your Padrino application. Note that
|
84
75
|
the models (and migrations) generated are specifically tailored towards the ORM component and testing framework
|
@@ -111,7 +102,7 @@ You can destroy models that you created via the destroy option and setting it to
|
|
111
102
|
|
112
103
|
This remove all created model files.
|
113
104
|
|
114
|
-
=== Migration Generator
|
105
|
+
=== Migration Generator
|
115
106
|
|
116
107
|
Padrino provides generator for quickly generating new migrations to change or manipulate the database schema.
|
117
108
|
These migrations generated will be tailored towards the ORM chosen when generating the application.
|
@@ -139,7 +130,7 @@ You can destroy migrations that you created via the destroy option and setting i
|
|
139
130
|
|
140
131
|
This removes the migration file.
|
141
132
|
|
142
|
-
=== Controller Generator
|
133
|
+
=== Controller Generator
|
143
134
|
|
144
135
|
Padrino provides generator support for quickly creating new controllers within your Padrino application. Note that
|
145
136
|
the controller tests are generated specifically tailored towards the testing framework chosen
|
@@ -170,7 +161,7 @@ You can destroy controllers that you created via the destroy option and setting
|
|
170
161
|
|
171
162
|
This removes all created controller files.
|
172
163
|
|
173
|
-
=== Mailer Generator
|
164
|
+
=== Mailer Generator
|
174
165
|
|
175
166
|
Padrino provides generator support for quickly creating new mailers within your Padrino application.
|
176
167
|
Very important to note that mailer generators are intended primarily to work within applications
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.2
|
data/bin/padrino-gen
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
%w[rubygems thor].each { |gem| require gem }
|
3
|
-
|
3
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
# We try to load the vendored padrino-core if exist
|
6
|
+
if File.exist?(File.dirname(__FILE__) + "/../../padrino-core/lib")
|
7
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../../padrino-core/lib"
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
generator_class = Padrino::Generators.mappings[generator_kind]
|
10
|
+
require 'padrino-gen'
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
puts "Please specify generator to use (#{Padrino::Generators.mappings.keys.join(", ")})"
|
15
|
-
end
|
12
|
+
# We need our config boot because we need to load registered generators so:
|
13
|
+
Padrino::Generators::Cli.start(ARGV)
|
@@ -78,19 +78,19 @@ module Padrino
|
|
78
78
|
end.max.to_i || 0
|
79
79
|
end
|
80
80
|
|
81
|
-
#For model destroy option
|
82
|
-
#removes the initial migration file of model
|
81
|
+
# For model destroy option
|
82
|
+
# removes the initial migration file of model
|
83
83
|
def remove_model_migration(name)
|
84
84
|
remove_migration "Create" + name
|
85
85
|
end
|
86
86
|
|
87
|
-
#For the removal of migration files
|
87
|
+
# For the removal of migration files
|
88
88
|
# removes the migration file based on the migration name
|
89
89
|
def remove_migration(name)
|
90
90
|
migration_path = Dir[app_root_path('db/migrate/*.rb')].select do |f|
|
91
91
|
File.basename(f).match(/#{name.to_s.underscore}/)
|
92
92
|
end.first
|
93
|
-
remove_file migration_path
|
93
|
+
remove_file migration_path if migration_path && File.exist?(migration_path)
|
94
94
|
end
|
95
95
|
|
96
96
|
# For testing components
|
@@ -23,6 +23,7 @@ module Padrino
|
|
23
23
|
argument :fields, :desc => "The fields for the model", :type => :array, :default => []
|
24
24
|
class_option :root, :aliases => '-r', :default => nil, :type => :string
|
25
25
|
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
26
|
+
class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
|
26
27
|
|
27
28
|
# Show help if no argv given
|
28
29
|
def self.start(given_args=ARGV, config={})
|
@@ -39,7 +40,7 @@ module Padrino
|
|
39
40
|
migration_name = "create_#{name.pluralize.underscore}"
|
40
41
|
create_model_file(name, fields)
|
41
42
|
generate_model_test(name)
|
42
|
-
create_model_migration(migration_name, name, fields)
|
43
|
+
create_model_migration(migration_name, name, fields) unless options[:skip_migration]
|
43
44
|
else
|
44
45
|
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
|
45
46
|
end
|
@@ -18,5 +18,41 @@ module Padrino
|
|
18
18
|
load_paths.each { |lib| require lib }
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
class Cli < Thor::Group
|
23
|
+
|
24
|
+
# Include related modules
|
25
|
+
include Thor::Actions
|
26
|
+
|
27
|
+
class_option :root, :aliases => '-r', :default => nil, :type => :string
|
28
|
+
|
29
|
+
# We need to TRY to load boot because some of our app dependencies maybe have
|
30
|
+
# custom generators, so is necessary know who are.
|
31
|
+
def load_boot
|
32
|
+
if options[:root]
|
33
|
+
require File.join(options[:root], 'config/boot.rb') if File.exist?(File.join(options[:root], 'config/boot.rb'))
|
34
|
+
else
|
35
|
+
require 'config/boot.rb' if File.exist?('config/boot.rb')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup
|
40
|
+
require 'padrino-gen/generators/actions'
|
41
|
+
Dir[File.dirname(__FILE__) + '/generators/{components}/**/*.rb'].each { |lib| require lib }
|
42
|
+
|
43
|
+
Padrino::Generators.lockup!
|
44
|
+
|
45
|
+
generator_kind = ARGV.delete_at(0).to_s.downcase.to_sym if ARGV[0].present?
|
46
|
+
generator_class = Padrino::Generators.mappings[generator_kind]
|
47
|
+
|
48
|
+
if generator_class
|
49
|
+
generator_class.start(ARGV)
|
50
|
+
else
|
51
|
+
puts "Please specify generator to use (#{Padrino::Generators.mappings.keys.join(", ")})"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
21
57
|
end
|
22
58
|
end
|
@@ -0,0 +1,325 @@
|
|
1
|
+
if defined?(ActiveRecord)
|
2
|
+
namespace :ar do
|
3
|
+
namespace :create do
|
4
|
+
desc 'Create all the local databases defined in config/database.yml'
|
5
|
+
task :all => :environment do
|
6
|
+
ActiveRecord::Base.configurations.each_value do |config|
|
7
|
+
# Skip entries that don't have a database key, such as the first entry here:
|
8
|
+
#
|
9
|
+
# defaults: &defaults
|
10
|
+
# adapter: mysql
|
11
|
+
# username: root
|
12
|
+
# password:
|
13
|
+
# host: localhost
|
14
|
+
#
|
15
|
+
# development:
|
16
|
+
# database: blog_development
|
17
|
+
# <<: *defaults
|
18
|
+
next unless config['database']
|
19
|
+
# Only connect to local databases
|
20
|
+
local_database?(config) { create_database(config) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Create the database defined in config/database.yml for the current Padrino.env'
|
26
|
+
task :create => :environment do
|
27
|
+
create_database(ActiveRecord::Base.configurations[Padrino.env])
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_database(config)
|
31
|
+
begin
|
32
|
+
if config['adapter'] =~ /sqlite/
|
33
|
+
if File.exist?(config['database'])
|
34
|
+
$stderr.puts "#{config['database']} already exists"
|
35
|
+
else
|
36
|
+
begin
|
37
|
+
# Create the SQLite database
|
38
|
+
ActiveRecord::Base.establish_connection(config)
|
39
|
+
ActiveRecord::Base.connection
|
40
|
+
rescue
|
41
|
+
$stderr.puts $!, *($!.backtrace)
|
42
|
+
$stderr.puts "Couldn't create database for #{config.inspect}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
return # Skip the else clause of begin/rescue
|
46
|
+
else
|
47
|
+
ActiveRecord::Base.establish_connection(config)
|
48
|
+
ActiveRecord::Base.connection
|
49
|
+
end
|
50
|
+
rescue
|
51
|
+
case config['adapter']
|
52
|
+
when 'mysql'
|
53
|
+
@charset = ENV['CHARSET'] || 'utf8'
|
54
|
+
@collation = ENV['COLLATION'] || 'utf8_unicode_ci'
|
55
|
+
creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
|
56
|
+
begin
|
57
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
58
|
+
ActiveRecord::Base.connection.create_database(config['database'], creation_options)
|
59
|
+
ActiveRecord::Base.establish_connection(config)
|
60
|
+
rescue Mysql::Error => sqlerr
|
61
|
+
if sqlerr.errno == Mysql::Error::ER_ACCESS_DENIED_ERROR
|
62
|
+
print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
|
63
|
+
root_password = $stdin.gets.strip
|
64
|
+
grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \
|
65
|
+
"TO '#{config['username']}'@'localhost' " \
|
66
|
+
"IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;"
|
67
|
+
ActiveRecord::Base.establish_connection(config.merge(
|
68
|
+
'database' => nil, 'username' => 'root', 'password' => root_password))
|
69
|
+
ActiveRecord::Base.connection.create_database(config['database'], creation_options)
|
70
|
+
ActiveRecord::Base.connection.execute grant_statement
|
71
|
+
ActiveRecord::Base.establish_connection(config)
|
72
|
+
else
|
73
|
+
$stderr.puts sqlerr.error
|
74
|
+
$stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation}"
|
75
|
+
$stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset']
|
76
|
+
end
|
77
|
+
end
|
78
|
+
when 'postgresql'
|
79
|
+
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
|
80
|
+
begin
|
81
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
82
|
+
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
|
83
|
+
ActiveRecord::Base.establish_connection(config)
|
84
|
+
rescue
|
85
|
+
$stderr.puts $!, *($!.backtrace)
|
86
|
+
$stderr.puts "Couldn't create database for #{config.inspect}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
else
|
90
|
+
$stderr.puts "#{config['database']} already exists"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
namespace :drop do
|
95
|
+
desc 'Drops all the local databases defined in config/database.yml'
|
96
|
+
task :all => :environment do
|
97
|
+
ActiveRecord::Base.configurations.each_value do |config|
|
98
|
+
# Skip entries that don't have a database key
|
99
|
+
next unless config['database']
|
100
|
+
begin
|
101
|
+
# Only connect to local databases
|
102
|
+
local_database?(config) { drop_database(config) }
|
103
|
+
rescue Exception => e
|
104
|
+
puts "Couldn't drop #{config['database']} : #{e.inspect}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
desc 'Drops the database for the current Padrino.env'
|
111
|
+
task :drop => :environment do
|
112
|
+
config = ActiveRecord::Base.configurations[Padrino.env || 'development']
|
113
|
+
begin
|
114
|
+
drop_database(config)
|
115
|
+
rescue Exception => e
|
116
|
+
puts "Couldn't drop #{config['database']} : #{e.inspect}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def local_database?(config, &block)
|
121
|
+
if %w( 127.0.0.1 localhost ).include?(config['host']) || config['host'].blank?
|
122
|
+
yield
|
123
|
+
else
|
124
|
+
puts "This task only modifies local databases. #{config['database']} is on a remote host."
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking db:schema:dump. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
|
130
|
+
task :migrate => :environment do
|
131
|
+
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
132
|
+
ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
133
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
134
|
+
end
|
135
|
+
|
136
|
+
namespace :migrate do
|
137
|
+
desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
|
138
|
+
task :redo => :environment do
|
139
|
+
if ENV["VERSION"]
|
140
|
+
Rake::Task["db:migrate:down"].invoke
|
141
|
+
Rake::Task["db:migrate:up"].invoke
|
142
|
+
else
|
143
|
+
Rake::Task["db:rollback"].invoke
|
144
|
+
Rake::Task["db:migrate"].invoke
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
desc 'Resets your database using your migrations for the current environment'
|
149
|
+
task :reset => ["db:drop", "db:create", "db:migrate"]
|
150
|
+
|
151
|
+
desc 'Runs the "up" for a given migration VERSION.'
|
152
|
+
task :up => :environment do
|
153
|
+
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
154
|
+
raise "VERSION is required" unless version
|
155
|
+
ActiveRecord::Migrator.run(:up, "db/migrate/", version)
|
156
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
157
|
+
end
|
158
|
+
|
159
|
+
desc 'Runs the "down" for a given migration VERSION.'
|
160
|
+
task :down => :environment do
|
161
|
+
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
162
|
+
raise "VERSION is required" unless version
|
163
|
+
ActiveRecord::Migrator.run(:down, "db/migrate/", version)
|
164
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
|
169
|
+
task :rollback => :environment do
|
170
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
171
|
+
ActiveRecord::Migrator.rollback('db/migrate/', step)
|
172
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
173
|
+
end
|
174
|
+
|
175
|
+
desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
|
176
|
+
task :forward => :environment do
|
177
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
178
|
+
ActiveRecord::Migrator.forward('db/migrate/', step)
|
179
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
180
|
+
end
|
181
|
+
|
182
|
+
desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
|
183
|
+
task :reset => [ 'db:drop', 'db:setup' ]
|
184
|
+
|
185
|
+
desc "Retrieves the charset for the current environment's database"
|
186
|
+
task :charset => :environment do
|
187
|
+
config = ActiveRecord::Base.configurations[Padrino.env || 'development']
|
188
|
+
case config['adapter']
|
189
|
+
when 'mysql'
|
190
|
+
ActiveRecord::Base.establish_connection(config)
|
191
|
+
puts ActiveRecord::Base.connection.charset
|
192
|
+
when 'postgresql'
|
193
|
+
ActiveRecord::Base.establish_connection(config)
|
194
|
+
puts ActiveRecord::Base.connection.encoding
|
195
|
+
else
|
196
|
+
puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
desc "Retrieves the collation for the current environment's database"
|
201
|
+
task :collation => :environment do
|
202
|
+
config = ActiveRecord::Base.configurations[Padrino.env || 'development']
|
203
|
+
case config['adapter']
|
204
|
+
when 'mysql'
|
205
|
+
ActiveRecord::Base.establish_connection(config)
|
206
|
+
puts ActiveRecord::Base.connection.collation
|
207
|
+
else
|
208
|
+
puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
desc "Retrieves the current schema version number"
|
213
|
+
task :version => :environment do
|
214
|
+
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
215
|
+
end
|
216
|
+
|
217
|
+
desc "Raises an error if there are pending migrations"
|
218
|
+
task :abort_if_pending_migrations => :environment do
|
219
|
+
if defined? ActiveRecord
|
220
|
+
pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
|
221
|
+
|
222
|
+
if pending_migrations.any?
|
223
|
+
puts "You have #{pending_migrations.size} pending migrations:"
|
224
|
+
pending_migrations.each do |pending_migration|
|
225
|
+
puts ' %4d %s' % [pending_migration.version, pending_migration.name]
|
226
|
+
end
|
227
|
+
abort %{Run "rake db:migrate" to update your database then try again.}
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
desc 'Create the database, load the schema, and initialize with the seed data'
|
233
|
+
task :setup => [ 'db:create', 'db:schema:load', 'db:seed' ]
|
234
|
+
|
235
|
+
namespace :schema do
|
236
|
+
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
|
237
|
+
task :dump => :environment do
|
238
|
+
require 'active_record/schema_dumper'
|
239
|
+
File.open(ENV['SCHEMA'] || Padrino.root("db", "schema.rb"), "w") do |file|
|
240
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
241
|
+
end
|
242
|
+
Rake::Task["db:schema:dump"].reenable
|
243
|
+
end
|
244
|
+
|
245
|
+
desc "Load a schema.rb file into the database"
|
246
|
+
task :load => :environment do
|
247
|
+
file = ENV['SCHEMA'] || Padrino.root("db", "schema.rb")
|
248
|
+
if File.exists?(file)
|
249
|
+
load(file)
|
250
|
+
else
|
251
|
+
raise %{#{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 #{Padrino.root}/config/boot.rb to limit the frameworks that will be loaded}
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
namespace :structure do
|
257
|
+
desc "Dump the database structure to a SQL file"
|
258
|
+
task :dump => :environment do
|
259
|
+
abcs = ActiveRecord::Base.configurations
|
260
|
+
case abcs[Padrino.env]["adapter"]
|
261
|
+
when "mysql", "oci", "oracle"
|
262
|
+
ActiveRecord::Base.establish_connection(abcs[Padrino.env])
|
263
|
+
File.open("#{Padrino.root}/db/#{Padrino.env}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
|
264
|
+
when "postgresql"
|
265
|
+
ENV['PGHOST'] = abcs[Padrino.env]["host"] if abcs[Padrino.env]["host"]
|
266
|
+
ENV['PGPORT'] = abcs[Padrino.env]["port"].to_s if abcs[Padrino.env]["port"]
|
267
|
+
ENV['PGPASSWORD'] = abcs[Padrino.env]["password"].to_s if abcs[Padrino.env]["password"]
|
268
|
+
search_path = abcs[Padrino.env]["schema_search_path"]
|
269
|
+
unless search_path.blank?
|
270
|
+
search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
|
271
|
+
end
|
272
|
+
`pg_dump -i -U "#{abcs[Padrino.env]["username"]}" -s -x -O -f db/#{Padrino.env}_structure.sql #{search_path} #{abcs[Padrino.env]["database"]}`
|
273
|
+
raise "Error dumping database" if $?.exitstatus == 1
|
274
|
+
when "sqlite", "sqlite3"
|
275
|
+
dbfile = abcs[Padrino.env]["database"] || abcs[Padrino.env]["dbfile"]
|
276
|
+
`#{abcs[Padrino.env]["adapter"]} #{dbfile} .schema > db/#{Padrino.env}_structure.sql`
|
277
|
+
when "sqlserver"
|
278
|
+
`scptxfr /s #{abcs[Padrino.env]["host"]} /d #{abcs[Padrino.env]["database"]} /I /f db\\#{Padrino.env}_structure.sql /q /A /r`
|
279
|
+
`scptxfr /s #{abcs[Padrino.env]["host"]} /d #{abcs[Padrino.env]["database"]} /I /F db\ /q /A /r`
|
280
|
+
when "firebird"
|
281
|
+
set_firebird_env(abcs[Padrino.env])
|
282
|
+
db_string = firebird_db_string(abcs[Padrino.env])
|
283
|
+
sh "isql -a #{db_string} > #{Padrino.root}/db/#{Padrino.env}_structure.sql"
|
284
|
+
else
|
285
|
+
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
286
|
+
end
|
287
|
+
|
288
|
+
if ActiveRecord::Base.connection.supports_migrations?
|
289
|
+
File.open("#{Padrino.root}/db/#{Padrino.env}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
end
|
295
|
+
|
296
|
+
def drop_database(config)
|
297
|
+
case config['adapter']
|
298
|
+
when 'mysql'
|
299
|
+
ActiveRecord::Base.establish_connection(config)
|
300
|
+
ActiveRecord::Base.connection.drop_database config['database']
|
301
|
+
when /^sqlite/
|
302
|
+
require 'pathname'
|
303
|
+
path = Pathname.new(config['database'])
|
304
|
+
file = path.absolute? ? path.to_s : Padrino.root(path)
|
305
|
+
|
306
|
+
FileUtils.rm(file)
|
307
|
+
when 'postgresql'
|
308
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
309
|
+
ActiveRecord::Base.connection.drop_database config['database']
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def session_table_name
|
314
|
+
ActiveRecord::SessionStore::Session.table_name
|
315
|
+
end
|
316
|
+
|
317
|
+
def set_firebird_env(config)
|
318
|
+
ENV["ISC_USER"] = config["username"].to_s if config["username"]
|
319
|
+
ENV["ISC_PASSWORD"] = config["password"].to_s if config["password"]
|
320
|
+
end
|
321
|
+
|
322
|
+
def firebird_db_string(config)
|
323
|
+
FireRuby::Database.db_string_for(config.symbolize_keys)
|
324
|
+
end
|
325
|
+
end
|
@@ -1,15 +1,83 @@
|
|
1
1
|
if defined?(DataMapper)
|
2
2
|
namespace :dm do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
namespace :auto do
|
4
|
+
desc "Perform automigration (reset your db data)"
|
5
|
+
task :migrate => :environment do
|
6
|
+
::DataMapper.auto_migrate!
|
7
|
+
puts "<= dm:auto:migrate executed"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Perform non destructive automigration"
|
11
|
+
task :upgrade => :environment do
|
12
|
+
::DataMapper.auto_upgrade!
|
13
|
+
puts "<= dm:auto:upgrade executed"
|
14
|
+
end
|
7
15
|
end
|
8
16
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
17
|
+
namespace :migrate do
|
18
|
+
task :load => :environment do
|
19
|
+
require 'dm-migrations/migration_runner'
|
20
|
+
FileList["db/migrate/*.rb"].each do |migration|
|
21
|
+
load migration
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Migrate up using migrations"
|
26
|
+
task :up, :version, :needs => :load do |t, args|
|
27
|
+
version = args[:version] || ENV['VERSION']
|
28
|
+
migrate_up!(version)
|
29
|
+
puts "<= dm:migrate:up #{version} executed"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Migrate down using migrations"
|
33
|
+
task :down, :version, :needs => :load do |t, args|
|
34
|
+
version = args[:version] || ENV['VERSION']
|
35
|
+
migrate_down!(version)
|
36
|
+
puts "<= dm:migrate:down #{version} executed"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Migrate the database to the latest version"
|
41
|
+
task :migrate => 'dm:migrate:up'
|
42
|
+
|
43
|
+
desc "Create the database"
|
44
|
+
task :create => :environment do
|
45
|
+
config = DataMapper.repository.adapter.options.symbolize_keys
|
46
|
+
puts "=> Creating database #{config[:database]}"
|
47
|
+
case config[:adapter]
|
48
|
+
when 'postgres'
|
49
|
+
`createdb -U #{config[:username]} #{config[:database]}`
|
50
|
+
puts "<= dm:create executed"
|
51
|
+
when 'mysql'
|
52
|
+
user, password, database = config[:username], config[:password], config[:database]
|
53
|
+
`mysql -u #{user} #{password ? "-p #{password}" : ''} -e "create database #{database}"`
|
54
|
+
puts "<= dm:create executed"
|
55
|
+
when 'sqlite3'
|
56
|
+
Rake::Task['dm:auto:migrate'].invoke
|
57
|
+
else
|
58
|
+
raise "Adapter #{config[:adapter]} not supported for creating databases yet."
|
59
|
+
end
|
13
60
|
end
|
61
|
+
|
62
|
+
desc "Drop the database (postgres and mysql only)"
|
63
|
+
task :drop => :environment do
|
64
|
+
config = DataMapper.repository.adapter.options.symbolize_keys
|
65
|
+
puts "=> Dropping database '#{config[:database]}'"
|
66
|
+
case config[:adapter]
|
67
|
+
when 'postgres'
|
68
|
+
`dropdb -U #{config[:username]} #{config[:database]}`
|
69
|
+
puts "<= dm:drop executed"
|
70
|
+
when 'mysql'
|
71
|
+
user, password, database = config[:username], config[:password], config[:database]
|
72
|
+
`mysql -u #{user} #{password ? "-p #{password}" : ''} -e "drop database #{database}"`
|
73
|
+
puts "<= dm:drop executed"
|
74
|
+
else
|
75
|
+
raise "Adapter #{config[:adapter]} not supported for dropping databases yet.\ntry dm:auto:migrate"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "Drop the database, and migrate from scratch"
|
80
|
+
task :reset => [:drop, :create, :migrate]
|
81
|
+
|
14
82
|
end
|
15
83
|
end
|
data/lib/padrino-gen.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
require 'padrino-core/support_lite'
|
2
|
-
|
3
|
-
Dir[File.dirname(__FILE__) + '/padrino-gen/generators/{components}/**/*.rb'].each { |lib| require lib }
|
4
|
-
require File.dirname(__FILE__) + '/padrino-gen/generators/actions'
|
5
|
-
require File.dirname(__FILE__) + '/padrino-gen/generators/base'
|
6
|
-
require File.dirname(__FILE__) + '/padrino-gen/generators'
|
7
|
-
|
8
|
-
|
2
|
+
require 'padrino-gen/generators'
|
9
3
|
# Add our rakes when padrino core require this file.
|
10
4
|
require 'padrino-core/tasks'
|
11
5
|
Padrino::Tasks.files << Dir[File.dirname(__FILE__) + "/padrino-gen/padrino-tasks/**/*.rb"]
|
data/padrino-gen.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-gen}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
@@ -45,7 +45,6 @@ Gem::Specification.new do |s|
|
|
45
45
|
"lib/padrino-gen/generators/app/config/initializers/.empty_directory",
|
46
46
|
"lib/padrino-gen/generators/app/config/initializers/example.rb",
|
47
47
|
"lib/padrino-gen/generators/app/tmp/.empty_directory",
|
48
|
-
"lib/padrino-gen/generators/base.rb",
|
49
48
|
"lib/padrino-gen/generators/components/actions.rb",
|
50
49
|
"lib/padrino-gen/generators/components/mocks/mocha_gen.rb",
|
51
50
|
"lib/padrino-gen/generators/components/mocks/rr_gen.rb",
|
@@ -76,6 +75,7 @@ Gem::Specification.new do |s|
|
|
76
75
|
"lib/padrino-gen/generators/templates/scripts/lowpro.js",
|
77
76
|
"lib/padrino-gen/generators/templates/scripts/protopak.js",
|
78
77
|
"lib/padrino-gen/generators/templates/scripts/right.js",
|
78
|
+
"lib/padrino-gen/padrino-tasks/activerecord.rb",
|
79
79
|
"lib/padrino-gen/padrino-tasks/datamapper.rb",
|
80
80
|
"padrino-gen.gemspec",
|
81
81
|
"test/helper.rb",
|
@@ -98,7 +98,7 @@ Gem::Specification.new do |s|
|
|
98
98
|
|
99
99
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
100
100
|
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
|
101
|
-
s.add_runtime_dependency(%q<padrino-core>, ["= 0.6.
|
101
|
+
s.add_runtime_dependency(%q<padrino-core>, ["= 0.6.2"])
|
102
102
|
s.add_runtime_dependency(%q<thor>, [">= 0.11.8"])
|
103
103
|
s.add_runtime_dependency(%q<bundler>, [">= 0.5.0"])
|
104
104
|
s.add_development_dependency(%q<haml>, [">= 2.2.1"])
|
@@ -109,7 +109,7 @@ Gem::Specification.new do |s|
|
|
109
109
|
s.add_development_dependency(%q<fakeweb>, [">= 1.2.3"])
|
110
110
|
else
|
111
111
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
112
|
-
s.add_dependency(%q<padrino-core>, ["= 0.6.
|
112
|
+
s.add_dependency(%q<padrino-core>, ["= 0.6.2"])
|
113
113
|
s.add_dependency(%q<thor>, [">= 0.11.8"])
|
114
114
|
s.add_dependency(%q<bundler>, [">= 0.5.0"])
|
115
115
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
@@ -121,7 +121,7 @@ Gem::Specification.new do |s|
|
|
121
121
|
end
|
122
122
|
else
|
123
123
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
124
|
-
s.add_dependency(%q<padrino-core>, ["= 0.6.
|
124
|
+
s.add_dependency(%q<padrino-core>, ["= 0.6.2"])
|
125
125
|
s.add_dependency(%q<thor>, [">= 0.11.8"])
|
126
126
|
s.add_dependency(%q<bundler>, [">= 0.5.0"])
|
127
127
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
data/test/helper.rb
CHANGED
@@ -4,9 +4,19 @@ require 'shoulda'
|
|
4
4
|
require 'mocha'
|
5
5
|
require 'rack/test'
|
6
6
|
require 'webrat'
|
7
|
+
require 'thor'
|
8
|
+
|
9
|
+
# We try to load the vendored padrino-core if exist
|
10
|
+
%w(core).each do |gem|
|
11
|
+
if File.exist?(File.dirname(__FILE__) + "/../../padrino-#{gem}/lib")
|
12
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../../padrino-#{gem}/lib"
|
13
|
+
end
|
14
|
+
end
|
7
15
|
|
8
16
|
require 'padrino-gen'
|
9
17
|
|
18
|
+
Padrino::Generators::Cli.start
|
19
|
+
|
10
20
|
class Test::Unit::TestCase
|
11
21
|
include Rack::Test::Methods
|
12
22
|
include Webrat::Methods
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
requirements:
|
34
34
|
- - "="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 0.6.
|
36
|
+
version: 0.6.2
|
37
37
|
version:
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: thor
|
@@ -151,7 +151,6 @@ files:
|
|
151
151
|
- lib/padrino-gen/generators/app/config/initializers/.empty_directory
|
152
152
|
- lib/padrino-gen/generators/app/config/initializers/example.rb
|
153
153
|
- lib/padrino-gen/generators/app/tmp/.empty_directory
|
154
|
-
- lib/padrino-gen/generators/base.rb
|
155
154
|
- lib/padrino-gen/generators/components/actions.rb
|
156
155
|
- lib/padrino-gen/generators/components/mocks/mocha_gen.rb
|
157
156
|
- lib/padrino-gen/generators/components/mocks/rr_gen.rb
|
@@ -182,6 +181,7 @@ files:
|
|
182
181
|
- lib/padrino-gen/generators/templates/scripts/lowpro.js
|
183
182
|
- lib/padrino-gen/generators/templates/scripts/protopak.js
|
184
183
|
- lib/padrino-gen/generators/templates/scripts/right.js
|
184
|
+
- lib/padrino-gen/padrino-tasks/activerecord.rb
|
185
185
|
- lib/padrino-gen/padrino-tasks/datamapper.rb
|
186
186
|
- padrino-gen.gemspec
|
187
187
|
- test/helper.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
|
3
|
-
module Padrino
|
4
|
-
module Generators
|
5
|
-
|
6
|
-
class Base < Thor::Group
|
7
|
-
|
8
|
-
# Include related modules
|
9
|
-
include Thor::Actions
|
10
|
-
include Padrino::Generators::Actions
|
11
|
-
|
12
|
-
class_option :root, :aliases => '-r', :default => nil, :type => :string
|
13
|
-
|
14
|
-
def load_boot
|
15
|
-
if in_app_root?(options[:root])
|
16
|
-
require(options[:root] ? File.join(options[:root], 'config/boot.rb') : 'config/boot.rb')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|