daddy 0.11.1 → 0.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f7d4db72f3c9f1f8f96add5ad7f6da3ad7dea508c097f64d6db6c59928e38c1
4
- data.tar.gz: 0cc61f03619a743519bd616fcae5f208be60a720f134a0c57eaebb9a70b77d6d
3
+ metadata.gz: f71b758b41276f069327bb600ffc20ac7fafecf1245913333dee6f718dc72142
4
+ data.tar.gz: 10961fa1199db0e326ea388d95337822feb447afa55414786f3e82db412ca9b7
5
5
  SHA512:
6
- metadata.gz: 0f81db5a4cf6b5900ae9e2418494f293f9e7c0dde23705a300be7a83dc52fec73c4365117bcb5aa2365873f09e1debee8a59fffd97fe32233977301a94b8335d
7
- data.tar.gz: 5e2283c57da41945227b8cbdb27b5f8fe1b67e4511fa900eab7330d360d86a7cf2dea52c5f3328ec5583c67c186f7fbe1771d2b47dea1a8b3311f421d374787d
6
+ metadata.gz: 6786c310177fee7fb8cce31d7fdfc5145acccd65b5cc13b2d1aaea441eff058d5e7088a71256b3378debd01a6b622c9aeb6f66f49140369adfe0a3eb95fabcf0
7
+ data.tar.gz: 1176e6f9decb1fb0ec4fd1d427630a4ca68e2a123df34bc796f4e2b8060e56e911bc4d41b227494b7d4ae66eff6c7f3e6c57d2aac489d2c446e54b4112373b96
@@ -1,4 +1,4 @@
1
- version = ENV['RUBY_VERSION'] || '3.4.3'
1
+ version = ENV['RUBY_VERSION'] || '3.4.7'
2
2
  short_version = version.split('.')[0..1].join('.')
3
3
 
4
4
  execute "download ruby-#{version}" do
@@ -53,3 +53,8 @@ execute 'gem update --system 3.7.2 -N' do
53
53
  subscribes :run, "gem_package[bundler]", :immediately
54
54
  end
55
55
 
56
+ execute "bundle config set --global path ~/.gem/ruby/#{short_version}.0" do
57
+ user ENV['USER']
58
+ not_if "bundle config get path | grep -qE '\\.gem/ruby/#{short_version}.0'"
59
+ end
60
+
@@ -0,0 +1 @@
1
+ 23815a6d095696f7919090fdc3e2f9459b2c83d57224b2e446ce1f5f7333ef36 ruby-3.4.7.tar.gz
data/lib/daddy/version.rb CHANGED
@@ -2,6 +2,6 @@ module Daddy
2
2
  VERSION = [
3
3
  VERSION_MAJOR = '0',
4
4
  VERSION_MINOR = '11',
5
- VERSION_REVISION = '1'
5
+ VERSION_REVISION = '2'
6
6
  ].join('.')
7
7
  end
@@ -1,8 +1,9 @@
1
- require 'rake'
1
+ require_relative 'task_helper'
2
2
 
3
3
  namespace :dad do
4
4
  namespace :db do
5
-
5
+ include DatabaseHelpers
6
+
6
7
  desc 'database.yml に従ってDBを作成します。'
7
8
  task :create do
8
9
  config = YAML.safe_load(ERB.new(File.read('config/database.yml'), trim_mode: '-').result, aliases: true)
@@ -10,31 +11,71 @@ namespace :dad do
10
11
  FileUtils.mkdir_p("tmp")
11
12
  system("echo '# mysql ddl' > tmp/create_databases.sql")
12
13
 
13
- user = host = port = nil
14
+ # Collect all unique users from the target environment and databases
15
+ users = {}
16
+ host = port = nil
17
+
14
18
  config.each do |env, props|
15
19
  next if env == 'default'
16
- next if props['username'] == user
17
-
18
- user = props['username']
19
- host = props['host']
20
- port = props['port']
21
- system("echo 'drop user if exists \"#{user}\"@\"%\";' >> tmp/create_databases.sql")
22
- system("echo 'create user \"#{user}\"@\"%\" IDENTIFIED BY \"#{props['password']}\";' >> tmp/create_databases.sql")
20
+ next if ENV['RAILS_ENV'] and ENV['RAILS_ENV'] != env
21
+
22
+ if multiple_databases?(props)
23
+ # Multiple databases configuration (Rails 8 style)
24
+ props.each do |db_name, db_config|
25
+ next unless db_config.is_a?(Hash) && db_config['username']
26
+ username = db_config['username']
27
+ users[username] ||= {
28
+ 'password' => db_config['password'],
29
+ 'host' => db_config['host'],
30
+ 'port' => db_config['port']
31
+ }
32
+ host ||= db_config['host']
33
+ port ||= db_config['port']
34
+ end
35
+ else
36
+ # Single database configuration
37
+ next unless props['username']
38
+ username = props['username']
39
+ users[username] ||= {
40
+ 'password' => props['password'],
41
+ 'host' => props['host'],
42
+ 'port' => props['port']
43
+ }
44
+ host ||= props['host']
45
+ port ||= props['port']
46
+ end
47
+ end
48
+
49
+ # Create users
50
+ users.each do |username, user_info|
51
+ system("echo 'drop user if exists \"#{username}\"@\"%\";' >> tmp/create_databases.sql")
52
+ system("echo 'create user \"#{username}\"@\"%\" IDENTIFIED BY \"#{user_info['password']}\";' >> tmp/create_databases.sql")
23
53
  end
24
54
 
55
+ # Create databases
25
56
  config.each do |env, props|
26
57
  next if env == 'default'
27
58
  next if ENV['RAILS_ENV'] and ENV['RAILS_ENV'] != env
28
59
 
29
- system("echo 'drop database if exists #{props['database']};' >> tmp/create_databases.sql")
30
- system("echo 'create database #{props['database']};' >> tmp/create_databases.sql")
31
- system("echo 'grant all on #{props['database']}.* to #{user};' >> tmp/create_databases.sql")
32
-
33
- if ENV['FILE']
34
- system("echo 'grant all on #{props['database']}.* to #{user}@localhost;' >> tmp/create_databases.sql")
35
- system("echo 'grant file on *.* to #{user}@localhost;' >> tmp/create_databases.sql")
60
+ if multiple_databases?(props)
61
+ # Multiple databases configuration (Rails 8 style)
62
+ props.each do |db_name, db_config|
63
+ next unless db_config.is_a?(Hash) && db_config['database']
64
+ database = db_config['database']
65
+ username = db_config['username']
66
+
67
+ create_database_sql(database, username)
68
+ puts "database #{database} (#{env}/#{db_name}) written to tmp/create_databases.sql"
69
+ end
70
+ else
71
+ # Single database configuration
72
+ next unless props['database']
73
+ database = props['database']
74
+ username = props['username']
75
+
76
+ create_database_sql(database, username)
77
+ puts "database #{database} (#{env}) written to tmp/create_databases.sql"
36
78
  end
37
- puts "database for environment #{env} written to tmp/create_databases.sql"
38
79
  end
39
80
 
40
81
  system("echo 'flush privileges;' >> tmp/create_databases.sql")
@@ -139,4 +139,32 @@ def self.run_itamae(*recipes)
139
139
  end
140
140
 
141
141
  run "bundle exec itamae local #{options.join(' ')} #{recipe_files.join(' ')}"
142
+ end
143
+
144
+ # Database helper methods for dad:db namespace
145
+ module DatabaseHelpers
146
+ # Helper method to check if a configuration is multiple databases (Rails 8 style)
147
+ def multiple_databases?(props)
148
+ return false unless props.is_a?(Hash)
149
+ # Standard Rails database config keys
150
+ standard_keys = ['adapter', 'collation', 'database', 'encoding', 'host', 'max_connections', 'migrations_paths', 'password', 'port', 'url', 'username']
151
+ # If it has a 'database' key directly, it's a single database config
152
+ return false if props.key?('database')
153
+ # If it has keys that are not standard keys and those values are hashes with 'database' keys, it's multiple databases
154
+ props.any? do |key, value|
155
+ !standard_keys.include?(key.to_s) && value.is_a?(Hash) && value.key?('database')
156
+ end
157
+ end
158
+
159
+ # Helper method to write database creation SQL commands
160
+ def create_database_sql(database, username)
161
+ system("echo 'drop database if exists #{database};' >> tmp/create_databases.sql")
162
+ system("echo 'create database #{database};' >> tmp/create_databases.sql")
163
+ system("echo 'grant all on #{database}.* to \"#{username}\"@\"%\";' >> tmp/create_databases.sql")
164
+
165
+ if ENV['FILE']
166
+ system("echo 'grant all on #{database}.* to \"#{username}\"@localhost;' >> tmp/create_databases.sql")
167
+ system("echo 'grant file on *.* to \"#{username}\"@localhost;' >> tmp/create_databases.sql")
168
+ end
169
+ end
142
170
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ichy
@@ -293,6 +293,7 @@ files:
293
293
  - itamae/environments/ruby/ruby-2.7.8.tar.gz_sha256sum.txt
294
294
  - itamae/environments/ruby/ruby-3.2.9.tar.gz_sha256sum.txt
295
295
  - itamae/environments/ruby/ruby-3.4.3.tar.gz_sha256sum.txt
296
+ - itamae/environments/ruby/ruby-3.4.7.tar.gz_sha256sum.txt
296
297
  - itamae/locale/en.yml
297
298
  - itamae/locale/ja.yml
298
299
  - itamae/templates/etc/god/master.conf.erb