roda-project 0.1.7 → 0.1.8
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/lib/roda/project/bin/generators/migration.rb +2 -0
- data/lib/roda/project/bin/generators/routes.rb +3 -1
- data/lib/roda/project/cli.rb +2 -1
- data/lib/roda/project/main_context.rb +2 -0
- data/lib/roda/project/templates/base/scaffold/bin/roda.erb +67 -2
- data/lib/roda/project/version.rb +1 -1
- data/lib/roda/project.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e2e4f0e1a643cc30ca1efff43c571e29acf2ef47385c8fb6b5b1b1553641d6b
|
|
4
|
+
data.tar.gz: 0f81e9706caee934a023ba77243fc21447a39279719713e610c237136ae66a01
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f27ffba5ba456ec2d937f69f1781f58193fc27567bf0ac3d7ea83edad23e948f3d127b3f608ca354cec3746bad1dcba85203bcd529a64c156734a38ded7a9d2
|
|
7
|
+
data.tar.gz: 104494e4ff9bb346b440ac9b0be67d430653861079cdea90e99e813a7aad8236d63609bfbd0fb8bf2bb3043718e3fb6e8001cd5ccae59ee384a22eb4ba9123b8
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# rubocop:disable Layout/HeredocIndentation
|
|
1
2
|
class Roda
|
|
2
3
|
module Project
|
|
3
4
|
module Bin
|
|
@@ -92,7 +93,7 @@ class Roda
|
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
def routes_list
|
|
95
|
-
@routes_list ||= @args[1
|
|
96
|
+
@routes_list ||= @args[1..]
|
|
96
97
|
end
|
|
97
98
|
|
|
98
99
|
def branch_name
|
|
@@ -103,3 +104,4 @@ class Roda
|
|
|
103
104
|
end
|
|
104
105
|
end
|
|
105
106
|
end
|
|
107
|
+
# rubocop:enable Layout/HeredocIndentation
|
data/lib/roda/project/cli.rb
CHANGED
|
@@ -22,8 +22,9 @@ class Roda
|
|
|
22
22
|
puts "$ cd #{@context.project_name} && bundle"
|
|
23
23
|
if @context.database?
|
|
24
24
|
unless @context.sqlite?
|
|
25
|
-
puts "\n* create your database\n"
|
|
26
25
|
puts "\n* put your dev database credentials in app/config/config.rb\n"
|
|
26
|
+
puts "\n* create your database\n"
|
|
27
|
+
puts "$ bin/roda db create"
|
|
27
28
|
end
|
|
28
29
|
puts "\nmigrate the database (use RACK_ENV to migrate 'test' or 'production' environments):\n\n"
|
|
29
30
|
puts "$ bin/roda db migrate"
|
|
@@ -6,9 +6,8 @@ class Db < Thor
|
|
|
6
6
|
desc "migrate", "Migrate the database. Optional: provide target version, e.g., 'roda db:migrate 1'"
|
|
7
7
|
option :target, type: :numeric, aliases: "-t", desc: "provide target version"
|
|
8
8
|
def migrate
|
|
9
|
+
require_db_deps
|
|
9
10
|
require_relative "../boot"
|
|
10
|
-
require "sequel"
|
|
11
|
-
require "sequel/extensions/migration"
|
|
12
11
|
|
|
13
12
|
Sequel.extension :migration
|
|
14
13
|
db = Providers::DB::Conn.get
|
|
@@ -19,6 +18,72 @@ class Db < Thor
|
|
|
19
18
|
end
|
|
20
19
|
puts "* database migration complete."
|
|
21
20
|
end
|
|
21
|
+
<% if context.sqlite? %>
|
|
22
|
+
desc "create", "Create the database"
|
|
23
|
+
def create
|
|
24
|
+
require_db_deps
|
|
25
|
+
path = parse_sqlite_path(Config.get[:db][:url])
|
|
26
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
27
|
+
Sequel.connect("sqlite://#{path}") rescue nil
|
|
28
|
+
puts "* create database #{path} ✓"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
desc "drop", "Drop the database"
|
|
32
|
+
def drop
|
|
33
|
+
require_db_deps
|
|
34
|
+
path = parse_sqlite_path(Config.get[:db][:url])
|
|
35
|
+
File.delete(path) if File.exist?(path)
|
|
36
|
+
puts "* drop database #{path} ✓"
|
|
37
|
+
end
|
|
38
|
+
<% else %>
|
|
39
|
+
[:drop, :create].each do |action|
|
|
40
|
+
desc action.to_s, "#{action.capitalize} the database"
|
|
41
|
+
define_method(action) do
|
|
42
|
+
require_db_deps
|
|
43
|
+
require_relative "../app/config/config"<% if context.postgresql? %>
|
|
44
|
+
db_config =
|
|
45
|
+
PG::Connection
|
|
46
|
+
.conninfo_parse(Config.get[:db][:url])
|
|
47
|
+
.each_with_object({}) { |h, o|
|
|
48
|
+
o[h[:keyword].to_sym] = h[:val] if h[:val]
|
|
49
|
+
}
|
|
50
|
+
ok = system("PGPASSWORD='#{db_config[:password]}' #{action}db -h #{db_config[:host]} -p #{db_config[:port]} -U #{db_confi
|
|
51
|
+
g[:user]} #{db_config[:dbname]}")<% end %><% if context.mysql? %>
|
|
52
|
+
uri = URI.parse(Config.get[:db][:url])
|
|
53
|
+
db_config = {
|
|
54
|
+
host: uri.host,
|
|
55
|
+
port: uri.port,
|
|
56
|
+
user: uri.user,
|
|
57
|
+
password: uri.password,
|
|
58
|
+
dbname: uri.path.tr('/', '') # removes leading slash
|
|
59
|
+
}
|
|
60
|
+
sql = action == :create ?
|
|
61
|
+
"CREATE DATABASE IF NOT EXISTS `#{db_config[:dbname]}`;" :
|
|
62
|
+
"DROP DATABASE IF EXISTS `#{db_config[:dbname]}`;"
|
|
63
|
+
flags = []
|
|
64
|
+
flags << "-h#{db_config[:host]}" if db_config[:host]
|
|
65
|
+
flags << "-P#{db_config[:port]}" if db_config[:port]
|
|
66
|
+
flags << "-u#{db_config[:user]}" if db_config[:user]
|
|
67
|
+
env = { "MYSQL_PWD" => db_config[:password] }.compact
|
|
68
|
+
ok = system(env, "mysql", *flags, "-e", sql)<% end %>
|
|
69
|
+
puts "* #{action} database #{db_config[:dbname]} ✓" if ok
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
<% end %>
|
|
73
|
+
private
|
|
74
|
+
<% if context.sqlite? %>
|
|
75
|
+
def parse_sqlite_path(url)
|
|
76
|
+
uri = URI.parse(url)
|
|
77
|
+
File.expand_path(uri.host ? File.join(uri.host, uri.path) : uri.path, Dir.pwd)
|
|
78
|
+
end
|
|
79
|
+
<% end %>
|
|
80
|
+
def require_db_deps
|
|
81
|
+
require_relative "../boot"
|
|
82
|
+
require "sequel"
|
|
83
|
+
require "sequel/extensions/migration"
|
|
84
|
+
require "<%= context.db_gem %>"<% if context.mysql? %>
|
|
85
|
+
require "uri"<% end %>
|
|
86
|
+
end
|
|
22
87
|
end
|
|
23
88
|
<% end %>
|
|
24
89
|
class CLI < Thor
|
data/lib/roda/project/version.rb
CHANGED
data/lib/roda/project.rb
CHANGED
|
@@ -61,8 +61,8 @@ require_relative "project/generator"
|
|
|
61
61
|
require_relative "project/cli"
|
|
62
62
|
# Generators
|
|
63
63
|
require_relative "project/bin/generator"
|
|
64
|
-
require_relative
|
|
65
|
-
require_relative
|
|
64
|
+
require_relative "project/bin/generators/migration"
|
|
65
|
+
require_relative "project/bin/generators/routes"
|
|
66
66
|
require_relative "project/bin/generators"
|
|
67
67
|
# Version
|
|
68
68
|
require_relative "project/version"
|