runways 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/runways/generators/app_structure_generator.rb +19 -2
- data/lib/runways/generators/templates/db_config.tt +17 -0
- data/lib/runways/generators/templates/db_rake.tt +81 -0
- data/lib/runways/generators/templates/proto.tt +1 -1
- data/lib/runways/generators/templates/rakefile.tt +7 -0
- data/lib/runways/generators/templates/service.tt +5 -1
- data/lib/runways/version.rb +1 -1
- data/runways.gemspec +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 462747751a101183cf479cd462cf8a924929df86b323b9ad0b19844e1f4e537b
|
4
|
+
data.tar.gz: 4eeb8da232f3bb589b6c77de475c9f98d55635c23156c97e167d8f1eee064434
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f6a3e1cd8862c1d4ef8bd2479960c890d0dff68f684949f08059c68bcafd0509a337f566508cfdd70b0d756462bc2a02e2f0a9b0e8e46bcceaab5ab1e385597
|
7
|
+
data.tar.gz: 44e530f76eb06b082d2911331ab18de6e9a71ab89f90840276c59d7c2c5f635f4ac9729a1e291f36aea639766116e9467a508067a6154eaae91c9c5d9e20cbee
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -31,5 +31,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
31
31
|
Everyone interacting in the Runways project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/runways/blob/master/CODE_OF_CONDUCT.md).
|
32
32
|
|
33
33
|
## TODO
|
34
|
-
- [
|
34
|
+
- [*] Setup rake tasks for active record migrations
|
35
35
|
- [ ] Use ActiveRecord generators to handle ActiveRecord related tasks ( ex: generate migration, migrate, rollback )
|
@@ -15,11 +15,16 @@ class AppStructure < Thor::Group
|
|
15
15
|
models_directory = app_directory + "/models"
|
16
16
|
controller_directory = app_directory + "/controllers"
|
17
17
|
db_directory = root_directory + "/db"
|
18
|
+
migration_directory = db_directory + "/migrate"
|
18
19
|
lib_directory = root_directory + "/lib"
|
20
|
+
tasks_directory = lib_directory + "/tasks"
|
21
|
+
config_directory = root_directory + "/config"
|
19
22
|
|
20
23
|
create_following_dirs([
|
21
|
-
root_directory, app_directory,
|
22
|
-
|
24
|
+
root_directory, app_directory, config_directory,
|
25
|
+
lib_directory, tasks_directory,
|
26
|
+
models_directory, controller_directory,
|
27
|
+
db_directory, migration_directory,
|
23
28
|
])
|
24
29
|
end
|
25
30
|
|
@@ -32,6 +37,14 @@ class AppStructure < Thor::Group
|
|
32
37
|
template("templates/gemfile.tt", "#{name}/Gemfile")
|
33
38
|
end
|
34
39
|
|
40
|
+
def generate_db_rake_file
|
41
|
+
template("templates/db_rake.tt", "#{name}/lib/tasks/db.rake")
|
42
|
+
end
|
43
|
+
|
44
|
+
def generate_rake_file
|
45
|
+
template("templates/rakefile.tt", "#{name}/Rakefile")
|
46
|
+
end
|
47
|
+
|
35
48
|
def generate_application_record
|
36
49
|
template(
|
37
50
|
"templates/application_record.tt",
|
@@ -60,6 +73,10 @@ class AppStructure < Thor::Group
|
|
60
73
|
)
|
61
74
|
end
|
62
75
|
|
76
|
+
def generate_db_config_file
|
77
|
+
template("templates/db_config.tt", "#{name}/config/db_config.rb")
|
78
|
+
end
|
79
|
+
|
63
80
|
private
|
64
81
|
def create_following_dirs(dir_paths)
|
65
82
|
dir_paths.each do |dir_path|
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require './config/db_config'
|
3
|
+
|
4
|
+
namespace :db do
|
5
|
+
def establish_connection
|
6
|
+
ActiveRecord::Base.establish_connection(DbConfig.config)
|
7
|
+
end
|
8
|
+
|
9
|
+
def establish_admin_connection
|
10
|
+
ActiveRecord::Base.establish_connection(
|
11
|
+
DbConfig.config.except(:database)
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Create a database'
|
16
|
+
task :create do
|
17
|
+
establish_admin_connection
|
18
|
+
ActiveRecord::Base.connection.create_database(
|
19
|
+
DbConfig.config.fetch(:database)
|
20
|
+
)
|
21
|
+
Rake::Task['db:update_schema'].invoke
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Drop database'
|
25
|
+
task :drop do
|
26
|
+
establish_admin_connection
|
27
|
+
ActiveRecord::Base.connection.drop_database(
|
28
|
+
DbConfig.config.fetch(:database)
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Update Schema'
|
33
|
+
task :update_schema do
|
34
|
+
establish_connection
|
35
|
+
ActiveRecord::SchemaDumper.dump(
|
36
|
+
ActiveRecord::Base.connection,
|
37
|
+
File.new('schema.rb', 'w')
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Migrate the database'
|
42
|
+
task :migrate do
|
43
|
+
establish_connection
|
44
|
+
ActiveRecord::Migrator.migrate('db/migrate/')
|
45
|
+
Rake::Task['db:update_schema'].execute
|
46
|
+
puts 'Database migrated.'
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'Rollback the previous migration'
|
50
|
+
task :rollback do
|
51
|
+
establish_connection
|
52
|
+
ActiveRecord::Migrator.rollback('db/migrate/')
|
53
|
+
Rake::Task['db:update_schema'].invoke
|
54
|
+
puts 'Migration rolledback'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
namespace :g do
|
59
|
+
desc 'Generate migration'
|
60
|
+
task :migration do
|
61
|
+
name = ARGV[1] || raise('Specify name: rake g:migration your_migration')
|
62
|
+
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
63
|
+
path = File.expand_path(
|
64
|
+
"../../../db/migrate/#{timestamp}_#{name}.rb",
|
65
|
+
__FILE__
|
66
|
+
)
|
67
|
+
migration_class = name.split('_').map(&:capitalize).join
|
68
|
+
|
69
|
+
File.open(path, 'w') do |file|
|
70
|
+
file.write <<~EOF
|
71
|
+
class #{migration_class} < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
72
|
+
def change
|
73
|
+
end
|
74
|
+
end
|
75
|
+
EOF
|
76
|
+
end
|
77
|
+
|
78
|
+
puts "Migration #{path} created"
|
79
|
+
abort # needed stop other tasks
|
80
|
+
end
|
81
|
+
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
|
+
require './config/db_config'
|
3
4
|
|
4
5
|
Bundler.require(:default)
|
5
|
-
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection(
|
8
|
+
DbConfig.config
|
9
|
+
)
|
6
10
|
|
7
11
|
require './lib/protos/<%= name.underscore %>_services_pb'
|
8
12
|
require './config/initializers'
|
data/lib/runways/version.rb
CHANGED
data/runways.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runways
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NG
|
@@ -117,9 +117,12 @@ files:
|
|
117
117
|
- lib/runways.rb
|
118
118
|
- lib/runways/generators/app_structure_generator.rb
|
119
119
|
- lib/runways/generators/templates/application_record.tt
|
120
|
+
- lib/runways/generators/templates/db_config.tt
|
121
|
+
- lib/runways/generators/templates/db_rake.tt
|
120
122
|
- lib/runways/generators/templates/gemfile.tt
|
121
123
|
- lib/runways/generators/templates/models.tt
|
122
124
|
- lib/runways/generators/templates/proto.tt
|
125
|
+
- lib/runways/generators/templates/rakefile.tt
|
123
126
|
- lib/runways/generators/templates/server.tt
|
124
127
|
- lib/runways/generators/templates/service.tt
|
125
128
|
- lib/runways/version.rb
|