padrino-gen 0.16.0.pre4 → 0.16.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.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/bin/padrino-gen +4 -4
- data/lib/padrino-gen/command.rb +2 -2
- data/lib/padrino-gen/generators/actions.rb +68 -64
- data/lib/padrino-gen/generators/app/app.rb.tt +6 -6
- data/lib/padrino-gen/generators/app.rb +19 -19
- data/lib/padrino-gen/generators/cli.rb +16 -19
- data/lib/padrino-gen/generators/component.rb +18 -19
- data/lib/padrino-gen/generators/components/actions.rb +42 -42
- data/lib/padrino-gen/generators/components/mocks/mocha.rb +7 -7
- data/lib/padrino-gen/generators/components/mocks/rr.rb +7 -7
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +158 -156
- data/lib/padrino-gen/generators/components/orms/couchrest.rb +33 -33
- data/lib/padrino-gen/generators/components/orms/datamapper.rb +108 -103
- data/lib/padrino-gen/generators/components/orms/dynamoid.rb +40 -40
- data/lib/padrino-gen/generators/components/orms/minirecord.rb +114 -114
- data/lib/padrino-gen/generators/components/orms/mongoid.rb +65 -65
- data/lib/padrino-gen/generators/components/orms/mongomapper.rb +20 -20
- data/lib/padrino-gen/generators/components/orms/mongomatic.rb +63 -59
- data/lib/padrino-gen/generators/components/orms/ohm.rb +49 -47
- data/lib/padrino-gen/generators/components/orms/ripple.rb +45 -45
- data/lib/padrino-gen/generators/components/orms/sequel.rb +51 -46
- data/lib/padrino-gen/generators/components/renderers/erb.rb +1 -1
- data/lib/padrino-gen/generators/components/renderers/liquid.rb +1 -1
- data/lib/padrino-gen/generators/components/scripts/dojo.rb +6 -6
- data/lib/padrino-gen/generators/components/scripts/extcore.rb +6 -6
- data/lib/padrino-gen/generators/components/scripts/jquery.rb +6 -6
- data/lib/padrino-gen/generators/components/scripts/mootools.rb +6 -6
- data/lib/padrino-gen/generators/components/scripts/prototype.rb +8 -8
- data/lib/padrino-gen/generators/components/stylesheets/compass.rb +1 -1
- data/lib/padrino-gen/generators/components/stylesheets/less.rb +4 -4
- data/lib/padrino-gen/generators/components/tests/bacon.rb +66 -66
- data/lib/padrino-gen/generators/components/tests/cucumber.rb +61 -61
- data/lib/padrino-gen/generators/components/tests/minitest.rb +70 -70
- data/lib/padrino-gen/generators/components/tests/rspec.rb +74 -74
- data/lib/padrino-gen/generators/components/tests/shoulda.rb +72 -72
- data/lib/padrino-gen/generators/components/tests/testunit.rb +69 -69
- data/lib/padrino-gen/generators/controller.rb +16 -17
- data/lib/padrino-gen/generators/helper.rb +8 -9
- data/lib/padrino-gen/generators/mailer.rb +8 -9
- data/lib/padrino-gen/generators/migration.rb +6 -6
- data/lib/padrino-gen/generators/model.rb +20 -21
- data/lib/padrino-gen/generators/plugin.rb +9 -9
- data/lib/padrino-gen/generators/project/config/apps.rb.tt +4 -4
- data/lib/padrino-gen/generators/project/config/boot.rb +2 -2
- data/lib/padrino-gen/generators/project/config.ru +1 -1
- data/lib/padrino-gen/generators/project.rb +49 -51
- data/lib/padrino-gen/generators/runner.rb +25 -24
- data/lib/padrino-gen/generators/task.rb +7 -8
- data/lib/padrino-gen/generators/templates/Gemfile.tt +5 -5
- data/lib/padrino-gen/generators/templates/controller.rb.tt +3 -3
- data/lib/padrino-gen/generators/templates/mailer.rb.tt +15 -15
- data/lib/padrino-gen/generators/templates/project_bin.tt +1 -1
- data/lib/padrino-gen/generators/templates/task.rb.tt +1 -1
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +152 -160
- data/lib/padrino-gen/padrino-tasks/database.rb +2 -2
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +31 -31
- data/lib/padrino-gen/padrino-tasks/minirecord.rb +3 -3
- data/lib/padrino-gen/padrino-tasks/mongoid.rb +39 -41
- data/lib/padrino-gen/padrino-tasks/mongomapper.rb +18 -14
- data/lib/padrino-gen/padrino-tasks/sequel.rb +28 -28
- data/lib/padrino-gen/padrino-tasks/sql-helpers.rb +45 -45
- data/lib/padrino-gen.rb +4 -4
- data/padrino-gen.gemspec +19 -19
- data/test/fixtures/admin_template.rb +5 -5
- data/test/fixtures/database_template.rb +19 -22
- data/test/fixtures/example_template.rb +8 -8
- data/test/fixtures/git_template.rb +2 -2
- data/test/fixtures/plugin_template.rb +3 -3
- data/test/fixtures/rake_template.rb +5 -5
- data/test/helper.rb +23 -21
- data/test/test_app_generator.rb +13 -13
- data/test/test_cli.rb +4 -5
- data/test/test_component_generator.rb +17 -17
- data/test/test_controller_generator.rb +62 -63
- data/test/test_generator.rb +6 -6
- data/test/test_helper_generator.rb +23 -24
- data/test/test_mailer_generator.rb +7 -7
- data/test/test_migration_generator.rb +31 -31
- data/test/test_model_generator.rb +80 -80
- data/test/test_plugin_generator.rb +35 -36
- data/test/test_project_generator.rb +171 -169
- data/test/test_sql_helpers.rb +49 -50
- data/test/test_task_generator.rb +13 -13
- metadata +10 -10
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'English'
|
|
1
2
|
if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
2
3
|
# Fixes for Yardoc YRI Building
|
|
3
4
|
begin
|
|
@@ -10,8 +11,8 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
10
11
|
|
|
11
12
|
namespace :ar do
|
|
12
13
|
namespace :create do
|
|
13
|
-
desc
|
|
14
|
-
task :
|
|
14
|
+
desc 'Create all the local databases defined in config/database.yml'
|
|
15
|
+
task all: :skeleton do
|
|
15
16
|
with_all_databases do |config|
|
|
16
17
|
# Skip entries that don't have a database key, such as the first entry here:
|
|
17
18
|
#
|
|
@@ -31,67 +32,65 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
desc
|
|
35
|
-
task :
|
|
35
|
+
desc 'Creates the database defined in config/database.yml for the current Padrino.env'
|
|
36
|
+
task create: :skeleton do
|
|
36
37
|
with_database(Padrino.env) do |config|
|
|
37
38
|
create_database(config)
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
def create_database(config)
|
|
42
|
-
|
|
43
|
-
if config[:
|
|
44
|
-
|
|
45
|
-
$stderr.puts "#{config[:database]} already exists."
|
|
46
|
-
else
|
|
47
|
-
begin
|
|
48
|
-
# Create the SQLite database
|
|
49
|
-
FileUtils.mkdir_p File.dirname(config[:database]) unless File.exist?(File.dirname(config[:database]))
|
|
50
|
-
ActiveRecord::Base.establish_connection(config)
|
|
51
|
-
ActiveRecord::Base.connection
|
|
52
|
-
rescue StandardError => e
|
|
53
|
-
catch_error(:create, e, config)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
return # Skip the else clause of begin/rescue
|
|
43
|
+
if config[:adapter] =~ /sqlite/
|
|
44
|
+
if File.exist?(config[:database])
|
|
45
|
+
$stderr.puts "#{config[:database]} already exists."
|
|
57
46
|
else
|
|
58
|
-
ActiveRecord::Base.establish_connection(config)
|
|
59
|
-
ActiveRecord::Base.connection
|
|
60
|
-
end
|
|
61
|
-
rescue
|
|
62
|
-
case config[:adapter]
|
|
63
|
-
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
|
64
|
-
@charset = ENV['CHARSET'] || 'utf8'
|
|
65
|
-
@collation = ENV['COLLATION'] || 'utf8_unicode_ci'
|
|
66
|
-
creation_options = {:charset => (config[:charset] || @charset), :collation => (config[:collation] || @collation)}
|
|
67
47
|
begin
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
ActiveRecord::Base.establish_connection(config)
|
|
71
|
-
rescue StandardError => e
|
|
72
|
-
$stderr.puts *(e.backtrace)
|
|
73
|
-
$stderr.puts e.inspect
|
|
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
|
-
when 'postgresql'
|
|
78
|
-
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
|
|
79
|
-
begin
|
|
80
|
-
ActiveRecord::Base.establish_connection(config.merge(:database => 'postgres', :schema_search_path => 'public'))
|
|
81
|
-
ActiveRecord::Base.connection.create_database(config[:database], config.merge(:encoding => @encoding))
|
|
48
|
+
# Create the SQLite database
|
|
49
|
+
FileUtils.mkdir_p File.dirname(config[:database]) unless File.exist?(File.dirname(config[:database]))
|
|
82
50
|
ActiveRecord::Base.establish_connection(config)
|
|
51
|
+
ActiveRecord::Base.connection
|
|
83
52
|
rescue StandardError => e
|
|
84
53
|
catch_error(:create, e, config)
|
|
85
54
|
end
|
|
86
55
|
end
|
|
56
|
+
return # Skip the else clause of begin/rescue
|
|
87
57
|
else
|
|
88
|
-
|
|
58
|
+
ActiveRecord::Base.establish_connection(config)
|
|
59
|
+
ActiveRecord::Base.connection
|
|
60
|
+
end
|
|
61
|
+
rescue StandardError
|
|
62
|
+
case config[:adapter]
|
|
63
|
+
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
|
64
|
+
@charset = ENV['CHARSET'] || 'utf8'
|
|
65
|
+
@collation = ENV['COLLATION'] || 'utf8_unicode_ci'
|
|
66
|
+
creation_options = { charset: config[:charset] || @charset, collation: config[:collation] || @collation }
|
|
67
|
+
begin
|
|
68
|
+
ActiveRecord::Base.establish_connection(config.merge(database: nil))
|
|
69
|
+
ActiveRecord::Base.connection.create_database(config[:database], creation_options)
|
|
70
|
+
ActiveRecord::Base.establish_connection(config)
|
|
71
|
+
rescue StandardError => e
|
|
72
|
+
$stderr.puts(*e.backtrace)
|
|
73
|
+
$stderr.puts e.inspect
|
|
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
|
+
when 'postgresql'
|
|
78
|
+
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
|
|
79
|
+
begin
|
|
80
|
+
ActiveRecord::Base.establish_connection(config.merge(database: 'postgres', schema_search_path: 'public'))
|
|
81
|
+
ActiveRecord::Base.connection.create_database(config[:database], config.merge(encoding: @encoding))
|
|
82
|
+
ActiveRecord::Base.establish_connection(config)
|
|
83
|
+
rescue StandardError => e
|
|
84
|
+
catch_error(:create, e, config)
|
|
85
|
+
end
|
|
89
86
|
end
|
|
87
|
+
else
|
|
88
|
+
$stderr.puts "#{config[:database]} already exists"
|
|
90
89
|
end
|
|
91
90
|
|
|
92
91
|
namespace :drop do
|
|
93
|
-
desc
|
|
94
|
-
task :
|
|
92
|
+
desc 'Drops all the local databases defined in config/database.yml'
|
|
93
|
+
task all: :skeleton do
|
|
95
94
|
with_all_databases do |config|
|
|
96
95
|
# Skip entries that don't have a database key
|
|
97
96
|
next unless config[:database]
|
|
@@ -105,77 +104,70 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
105
104
|
end
|
|
106
105
|
end
|
|
107
106
|
|
|
108
|
-
desc
|
|
109
|
-
task :
|
|
107
|
+
desc 'Drops the database for the current Padrino.env'
|
|
108
|
+
task drop: :skeleton do
|
|
110
109
|
with_database(Padrino.env || :development) do |config|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
catch_error(:drop, e, config)
|
|
115
|
-
end
|
|
110
|
+
drop_database(config)
|
|
111
|
+
rescue StandardError => e
|
|
112
|
+
catch_error(:drop, e, config)
|
|
116
113
|
end
|
|
117
114
|
end
|
|
118
115
|
|
|
119
116
|
def local_database?(config, &block)
|
|
120
|
-
if %w
|
|
117
|
+
if %w[127.0.0.1 localhost].include?(config[:host]) || !config[:host]
|
|
121
118
|
yield
|
|
122
119
|
else
|
|
123
120
|
puts "This task only modifies local databases. #{config[:database]} is on a remote host."
|
|
124
121
|
end
|
|
125
122
|
end
|
|
126
123
|
|
|
127
|
-
desc
|
|
128
|
-
task :
|
|
129
|
-
ActiveRecord::Migration.verbose = ENV[
|
|
124
|
+
desc 'Migrate the database through scripts in db/migrate and update db/schema.rb by invoking ar:schema:dump. Target specific version with MIGRATION_VERSION=x. Turn off output with VERBOSE=false.'
|
|
125
|
+
task migrate: :skeleton do
|
|
126
|
+
ActiveRecord::Migration.verbose = ENV['VERBOSE'] ? ENV['VERBOSE'] == 'true' : true
|
|
130
127
|
|
|
131
128
|
if less_than_active_record_5_2?
|
|
132
|
-
ActiveRecord::Migrator.migrate(
|
|
133
|
-
elsif less_than_active_record_6_0?
|
|
134
|
-
ActiveRecord::MigrationContext.new("db/migrate/").migrate(env_migration_version)
|
|
129
|
+
ActiveRecord::Migrator.migrate('db/migrate/', env_migration_version)
|
|
135
130
|
else
|
|
136
|
-
|
|
131
|
+
migration_context.migrate(env_migration_version)
|
|
137
132
|
end
|
|
138
133
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
else
|
|
142
|
-
Rake::Task["ar:schema:dump"].invoke if ActiveRecord.schema_format == :ruby
|
|
143
|
-
end
|
|
134
|
+
format_source = ActiveRecord.respond_to?(:schema_format) ? ActiveRecord : ActiveRecord::Base
|
|
135
|
+
Rake::Task['ar:schema:dump'].invoke if format_source.schema_format == :ruby
|
|
144
136
|
end
|
|
145
137
|
|
|
146
138
|
namespace :migrate do
|
|
147
|
-
desc
|
|
148
|
-
task :
|
|
139
|
+
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 MIGRATION_VERSION=x.'
|
|
140
|
+
task redo: :skeleton do
|
|
149
141
|
if env_migration_version
|
|
150
|
-
Rake::Task[
|
|
151
|
-
Rake::Task[
|
|
142
|
+
Rake::Task['ar:migrate:down'].invoke
|
|
143
|
+
Rake::Task['ar:migrate:up'].invoke
|
|
152
144
|
else
|
|
153
|
-
Rake::Task[
|
|
154
|
-
Rake::Task[
|
|
145
|
+
Rake::Task['ar:rollback'].invoke
|
|
146
|
+
Rake::Task['ar:migrate'].invoke
|
|
155
147
|
end
|
|
156
148
|
end
|
|
157
149
|
|
|
158
|
-
desc
|
|
159
|
-
task :
|
|
150
|
+
desc 'Resets your database using your migrations for the current environment.'
|
|
151
|
+
task reset: ['ar:drop', 'ar:create', 'ar:migrate']
|
|
160
152
|
|
|
161
153
|
desc "Runs the 'up' for a given MIGRATION_VERSION."
|
|
162
|
-
task(:
|
|
154
|
+
task(up: :skeleton) { migrate_as(:up) }
|
|
163
155
|
|
|
164
156
|
desc "Runs the 'down' for a given MIGRATION_VERSION."
|
|
165
|
-
task(:
|
|
157
|
+
task(down: :skeleton) { migrate_as(:down) }
|
|
166
158
|
end
|
|
167
159
|
|
|
168
|
-
desc
|
|
169
|
-
task(:
|
|
160
|
+
desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
|
|
161
|
+
task(rollback: :skeleton) { move_as(:rollback) }
|
|
170
162
|
|
|
171
|
-
desc
|
|
172
|
-
task(:
|
|
163
|
+
desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
|
|
164
|
+
task(forward: :skeleton) { move_as(:forward) }
|
|
173
165
|
|
|
174
|
-
desc
|
|
175
|
-
task :
|
|
166
|
+
desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
|
|
167
|
+
task reset: ['ar:drop', 'ar:setup']
|
|
176
168
|
|
|
177
169
|
desc "Retrieves the charset for the current environment's database"
|
|
178
|
-
task :
|
|
170
|
+
task charset: :skeleton do
|
|
179
171
|
with_database(Padrino.env || :development) do |config|
|
|
180
172
|
case config[:adapter]
|
|
181
173
|
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
|
@@ -191,7 +183,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
191
183
|
end
|
|
192
184
|
|
|
193
185
|
desc "Retrieves the collation for the current environment's database."
|
|
194
|
-
task :
|
|
186
|
+
task collation: :skeleton do
|
|
195
187
|
with_database(Padrino.env || :development) do |config|
|
|
196
188
|
case config[:adapter]
|
|
197
189
|
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
|
@@ -203,82 +195,78 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
203
195
|
end
|
|
204
196
|
end
|
|
205
197
|
|
|
206
|
-
desc
|
|
207
|
-
task :
|
|
198
|
+
desc 'Retrieves the current schema version number.'
|
|
199
|
+
task version: :skeleton do
|
|
208
200
|
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
|
209
201
|
end
|
|
210
202
|
|
|
211
|
-
desc
|
|
212
|
-
task :
|
|
203
|
+
desc 'Raises an error if there are pending migrations.'
|
|
204
|
+
task abort_if_pending_migrations: :skeleton do
|
|
213
205
|
if defined? ActiveRecord
|
|
214
206
|
pending_migrations =
|
|
215
207
|
if less_than_active_record_5_2?
|
|
216
208
|
ActiveRecord::Migrator.open(ActiveRecord::Migrator.migrations_paths).pending_migrations
|
|
217
|
-
elsif less_than_active_record_6_0?
|
|
218
|
-
ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).open.pending_migrations
|
|
219
209
|
else
|
|
220
|
-
|
|
210
|
+
migration_context.open.pending_migrations
|
|
221
211
|
end
|
|
222
212
|
|
|
223
213
|
if pending_migrations.any?
|
|
224
214
|
puts "You have #{pending_migrations.size} pending migrations:"
|
|
225
215
|
pending_migrations.each do |pending_migration|
|
|
226
|
-
puts ' %4d %s'
|
|
216
|
+
puts format(' %4d %s', pending_migration.version, pending_migration.name)
|
|
227
217
|
end
|
|
228
|
-
abort %
|
|
218
|
+
abort %(Run "rake ar:migrate" to update your database then try again.)
|
|
229
219
|
end
|
|
230
220
|
end
|
|
231
221
|
end
|
|
232
222
|
|
|
233
|
-
desc
|
|
234
|
-
task :
|
|
223
|
+
desc 'Create the database, load the schema, and initialize with the seed data.'
|
|
224
|
+
task setup: ['ar:create', 'ar:schema:load', 'seed']
|
|
235
225
|
|
|
236
226
|
namespace :schema do
|
|
237
|
-
desc
|
|
238
|
-
task :
|
|
227
|
+
desc 'Create a db/schema.rb file that can be portably used against any DB supported by AR.'
|
|
228
|
+
task dump: :skeleton do
|
|
239
229
|
require 'active_record/schema_dumper'
|
|
240
|
-
File.open(ENV['SCHEMA'] || Padrino.root(
|
|
230
|
+
File.open(ENV['SCHEMA'] || Padrino.root('db', 'schema.rb'), 'w') do |file|
|
|
241
231
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
|
242
232
|
end
|
|
243
|
-
Rake::Task[
|
|
233
|
+
Rake::Task['ar:schema:dump'].reenable
|
|
244
234
|
end
|
|
245
235
|
|
|
246
|
-
desc
|
|
247
|
-
task :
|
|
248
|
-
file = ENV['SCHEMA'] || Padrino.root(
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
end
|
|
236
|
+
desc 'Load a schema.rb file into the database.'
|
|
237
|
+
task load: :skeleton do
|
|
238
|
+
file = ENV['SCHEMA'] || Padrino.root('db', 'schema.rb')
|
|
239
|
+
File.exist?(file) ? load(file) : raise(<<~MESSAGE.gsub("\n", ' '))
|
|
240
|
+
#{file} doesn't exist yet. Run "rake ar:migrate" to create it then try again.
|
|
241
|
+
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
|
|
242
|
+
MESSAGE
|
|
254
243
|
end
|
|
255
244
|
end
|
|
256
245
|
|
|
257
246
|
namespace :structure do
|
|
258
|
-
desc
|
|
259
|
-
task :
|
|
247
|
+
desc 'Dump the database structure to a SQL file.'
|
|
248
|
+
task dump: :skeleton do
|
|
260
249
|
with_database(Padrino.env) do |config|
|
|
261
250
|
case config[:adapter]
|
|
262
|
-
when
|
|
263
|
-
config
|
|
264
|
-
|
|
265
|
-
when "postgresql"
|
|
251
|
+
when 'mysql', 'mysql2', 'em_mysql2', 'oci', 'oracle', 'jdbcmysql'
|
|
252
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump(config.transform_keys(&:to_s), resolve_structure_sql)
|
|
253
|
+
when 'postgresql'
|
|
266
254
|
ENV['PGHOST'] = config[:host] if config[:host]
|
|
267
255
|
ENV['PGPORT'] = config[:port].to_s if config[:port]
|
|
268
256
|
ENV['PGPASSWORD'] = config[:password].to_s if config[:password]
|
|
257
|
+
|
|
269
258
|
search_path = config[:schema_search_path]
|
|
270
|
-
if search_path
|
|
271
|
-
|
|
272
|
-
end
|
|
259
|
+
search_path = search_path.split(',').map { |path| "--schema=#{path.strip}" }.join(' ') if search_path
|
|
260
|
+
|
|
273
261
|
`pg_dump -U "#{config[:username]}" -s -x -O -f db/#{Padrino.env}_structure.sql #{search_path} #{config[:database]}`
|
|
274
|
-
raise
|
|
275
|
-
when
|
|
262
|
+
raise 'Error dumping database' if $CHILD_STATUS.exitstatus == 1
|
|
263
|
+
when 'sqlite', 'sqlite3'
|
|
276
264
|
dbfile = config[:database] || config[:dbfile]
|
|
277
265
|
`#{config[:adapter]} #{dbfile} .schema > db/#{Padrino.env}_structure.sql`
|
|
278
|
-
when
|
|
266
|
+
when 'sqlserver'
|
|
279
267
|
`scptxfr /s #{config[:host]} /d #{config[:database]} /I /f db\\#{Padrino.env}_structure.sql /q /A /r`
|
|
280
268
|
`scptxfr /s #{config[:host]} /d #{config[:database]} /I /F db\ /q /A /r`
|
|
281
|
-
when
|
|
269
|
+
when 'firebird'
|
|
282
270
|
set_firebird_env(config)
|
|
283
271
|
db_string = firebird_db_string(config)
|
|
284
272
|
sh "isql -a #{db_string} > #{Padrino.root}/db/#{Padrino.env}_structure.sql"
|
|
@@ -288,14 +276,14 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
288
276
|
end
|
|
289
277
|
|
|
290
278
|
if !ActiveRecord::Base.connection.respond_to?(:supports_migrations?) || ActiveRecord::Base.connection.supports_migrations?
|
|
291
|
-
File.open(resolve_structure_sql,
|
|
279
|
+
File.open(resolve_structure_sql, 'a') { |f| f << ActiveRecord::Base.connection.dump_schema_information }
|
|
292
280
|
end
|
|
293
281
|
end
|
|
294
282
|
end
|
|
295
283
|
|
|
296
|
-
desc
|
|
297
|
-
task :
|
|
298
|
-
models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m,
|
|
284
|
+
desc 'Generates .yml files for I18n translations.'
|
|
285
|
+
task translate: :environment do
|
|
286
|
+
models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m, '.rb') }
|
|
299
287
|
|
|
300
288
|
models.each do |m|
|
|
301
289
|
# get the model class
|
|
@@ -319,23 +307,27 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
319
307
|
columns.each do |c|
|
|
320
308
|
locale += "\n #{c}: #{klass.human_attribute_name(c)}" unless locale.include?("#{c}:")
|
|
321
309
|
end
|
|
322
|
-
print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
|
|
323
310
|
else
|
|
324
|
-
locale
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
311
|
+
locale = <<~YAML
|
|
312
|
+
#{lang}:
|
|
313
|
+
models:
|
|
314
|
+
#{m}:
|
|
315
|
+
name: #{klass.model_name.human}
|
|
316
|
+
attributes:
|
|
317
|
+
YAML
|
|
318
|
+
|
|
319
|
+
columns.each { |c| locale += " #{c}: #{klass.human_attribute_name(c)}\n" }
|
|
320
|
+
locale.chomp!
|
|
331
321
|
end
|
|
332
|
-
|
|
322
|
+
|
|
323
|
+
$stdout.flush
|
|
324
|
+
File.open(filename, 'w') { |f| f.puts locale }
|
|
333
325
|
end
|
|
334
326
|
puts
|
|
335
327
|
end
|
|
336
328
|
end
|
|
337
329
|
|
|
338
|
-
task :
|
|
330
|
+
task seed: :environment do
|
|
339
331
|
missing_model_features = Padrino.send(:default_dependency_paths) - Padrino.send(:dependency_paths)
|
|
340
332
|
Padrino.require_dependencies(missing_model_features)
|
|
341
333
|
Rake::Task['db:seed'].invoke
|
|
@@ -354,14 +346,14 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
354
346
|
|
|
355
347
|
FileUtils.rm(file)
|
|
356
348
|
when 'postgresql'
|
|
357
|
-
ActiveRecord::Base.establish_connection(config.merge(:
|
|
349
|
+
ActiveRecord::Base.establish_connection(config.merge(database: 'postgres', schema_search_path: 'public'))
|
|
358
350
|
ActiveRecord::Base.connection.drop_database config[:database]
|
|
359
351
|
end
|
|
360
352
|
end
|
|
361
353
|
|
|
362
354
|
def set_firebird_env(config)
|
|
363
|
-
ENV[
|
|
364
|
-
ENV[
|
|
355
|
+
ENV['ISC_USER'] = config[:username].to_s if config[:username]
|
|
356
|
+
ENV['ISC_PASSWORD'] = config[:password].to_s if config[:password]
|
|
365
357
|
end
|
|
366
358
|
|
|
367
359
|
def firebird_db_string(config)
|
|
@@ -369,7 +361,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
369
361
|
end
|
|
370
362
|
|
|
371
363
|
def catch_error(type, error, config)
|
|
372
|
-
$stderr.puts
|
|
364
|
+
$stderr.puts(*error.backtrace)
|
|
373
365
|
$stderr.puts error.inspect
|
|
374
366
|
case type
|
|
375
367
|
when :create
|
|
@@ -381,14 +373,12 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
381
373
|
|
|
382
374
|
def migrate_as(type)
|
|
383
375
|
version = env_migration_version
|
|
384
|
-
|
|
376
|
+
raise 'MIGRATION_VERSION is required' unless version
|
|
385
377
|
|
|
386
378
|
if less_than_active_record_5_2?
|
|
387
|
-
ActiveRecord::Migrator.run(type,
|
|
388
|
-
elsif less_than_active_record_6_0?
|
|
389
|
-
ActiveRecord::MigrationContext.new('db/migrate/').run(type, version)
|
|
379
|
+
ActiveRecord::Migrator.run(type, 'db/migrate/', version)
|
|
390
380
|
else
|
|
391
|
-
|
|
381
|
+
migration_context.run(type, version)
|
|
392
382
|
end
|
|
393
383
|
|
|
394
384
|
dump_schema
|
|
@@ -399,17 +389,15 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
399
389
|
|
|
400
390
|
if less_than_active_record_5_2?
|
|
401
391
|
ActiveRecord::Migrator.send(type, 'db/migrate/', step)
|
|
402
|
-
elsif less_than_active_record_6_0?
|
|
403
|
-
ActiveRecord::MigrationContext.new('db/migrate/').send(type, step)
|
|
404
392
|
else
|
|
405
|
-
|
|
393
|
+
migration_context.send(type, step)
|
|
406
394
|
end
|
|
407
395
|
|
|
408
396
|
dump_schema
|
|
409
397
|
end
|
|
410
398
|
|
|
411
399
|
def dump_schema
|
|
412
|
-
Rake::Task[
|
|
400
|
+
Rake::Task['ar:schema:dump'].invoke if ActiveRecord::Base.schema_format == :ruby
|
|
413
401
|
end
|
|
414
402
|
|
|
415
403
|
def resolve_structure_sql
|
|
@@ -417,19 +405,25 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
417
405
|
end
|
|
418
406
|
|
|
419
407
|
def less_than_active_record_5_2?
|
|
420
|
-
ActiveRecord.version < Gem::Version.create(
|
|
408
|
+
ActiveRecord.version < Gem::Version.create('5.2.0')
|
|
421
409
|
end
|
|
422
410
|
|
|
423
411
|
def less_than_active_record_6_0?
|
|
424
|
-
ActiveRecord.version < Gem::Version.create(
|
|
412
|
+
ActiveRecord.version < Gem::Version.create('6.0.0')
|
|
425
413
|
end
|
|
426
414
|
|
|
427
415
|
def less_than_active_record_6_1?
|
|
428
|
-
ActiveRecord.version < Gem::Version.create(
|
|
416
|
+
ActiveRecord.version < Gem::Version.create('6.1.0')
|
|
429
417
|
end
|
|
430
418
|
|
|
431
|
-
def
|
|
432
|
-
|
|
419
|
+
def migration_context
|
|
420
|
+
if less_than_active_record_6_0?
|
|
421
|
+
ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
|
|
422
|
+
else
|
|
423
|
+
connection = ActiveRecord::Base.connection
|
|
424
|
+
connection = connection.pool unless connection.respond_to?(:migration_context)
|
|
425
|
+
connection.migration_context
|
|
426
|
+
end
|
|
433
427
|
end
|
|
434
428
|
|
|
435
429
|
def with_database(env_name)
|
|
@@ -446,14 +440,12 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
446
440
|
end
|
|
447
441
|
end
|
|
448
442
|
|
|
449
|
-
def with_all_databases
|
|
443
|
+
def with_all_databases(&block)
|
|
450
444
|
if less_than_active_record_6_0?
|
|
451
|
-
ActiveRecord::Base.configurations.each_value
|
|
452
|
-
yield config
|
|
453
|
-
end
|
|
445
|
+
ActiveRecord::Base.configurations.each_value(&block)
|
|
454
446
|
else
|
|
455
447
|
ActiveRecord::Base.configurations.configs_for.each do |db_config|
|
|
456
|
-
|
|
448
|
+
block.call(configuration_hash(db_config))
|
|
457
449
|
end
|
|
458
450
|
end
|
|
459
451
|
end
|
|
@@ -465,8 +457,8 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
|
465
457
|
end
|
|
466
458
|
|
|
467
459
|
task 'db:migrate' => 'ar:migrate'
|
|
468
|
-
task 'db:create'
|
|
469
|
-
task 'db:drop'
|
|
470
|
-
task 'db:reset'
|
|
471
|
-
task 'db:setup'
|
|
460
|
+
task 'db:create' => 'ar:create'
|
|
461
|
+
task 'db:drop' => 'ar:drop'
|
|
462
|
+
task 'db:reset' => 'ar:reset'
|
|
463
|
+
task 'db:setup' => 'ar:setup'
|
|
472
464
|
end
|
|
@@ -2,11 +2,11 @@ has_seeds = File.file?('db/seeds.rb')
|
|
|
2
2
|
if PadrinoTasks.load?(:database, has_seeds)
|
|
3
3
|
namespace :db do
|
|
4
4
|
desc 'Load the seed data from db/seeds.rb'
|
|
5
|
-
task :
|
|
5
|
+
task seed: :environment do
|
|
6
6
|
seed_file = Padrino.root('db', 'seeds.rb')
|
|
7
7
|
load(seed_file) if File.exist?(seed_file)
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
task :
|
|
11
|
+
task seed: 'db:seed'
|
|
12
12
|
end
|