arxutils_sqlite3 0.1.54 → 0.1.56

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63b6c2964eb5bd59b6601706fdb9085d50353be9df04ba6b83995e1c9b617707
4
- data.tar.gz: 3c366bd4cddb2287a82ad9f184a465c9953323699108eab8849ecadb10f8f11f
3
+ metadata.gz: 6c61855dd1cb824e99683ddbe8ea74085dccfdceb07daf5d875c17ae970ba764
4
+ data.tar.gz: 58b003297e61ab90072846de1b34836ac0a7461d3c611dee991224c6d07c0354
5
5
  SHA512:
6
- metadata.gz: b9c7c00307a6063f7254478e8879a0f883b4bb369533cb738dadbb964723cc24f7460e1684e9ae61b201567f3a13f48c8cb0e357999c7cdc99224cb9d6d9acb8
7
- data.tar.gz: 0f2c860830b7568161cede9212427412d1e9babe3426429541e425f5e032695976c2e8e91657c81f90e1ff47583f4920efadb37cb2c978da09c302d92b04aaa5
6
+ metadata.gz: 123d78945f9f2f2b8e23f944f111d069e92c94551523f51a13dce6e928722f031a3c399b66eb87be4973ec2f372bdb067ea78b36ea1df115d9382bccec9c70df
7
+ data.tar.gz: '08dcc25d6c3fc43b343ef65d08df6bdf789a6eed391f0af73deb5fbe348d8a8baca7a3086d19ab21bd42edd99cf1ab75c0d0b1da6012276c659589d99ff74292'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arxutils_sqlite3 (0.1.54)
4
+ arxutils_sqlite3 (0.1.56)
5
5
  activerecord (~> 6.1)
6
6
  activesupport
7
7
  simpleoptparse
data/exe/arxutils_sqlite3 CHANGED
@@ -13,10 +13,10 @@ opts, klass = config.setupx(self)
13
13
  # p klass
14
14
  # exit
15
15
 
16
- banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|cds|co|c|f|m|a|d|b|y) -y yaml_file --klass=class"
16
+ banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|cds|co|c|f|m|a|d|b|y|dm) -y yaml_file --klass=class"
17
17
 
18
18
  Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Arxutils_Sqlite3::VERSION, nil) do |parser|
19
- parser.on("--cmd X", %w[s cds co c f m a d b y]) { |x| opts["cmd"] = x }
19
+ parser.on("--cmd X", %w[s cds co c f m a d b y dm]) { |x| opts["cmd"] = x }
20
20
  parser.on("-y yaml_file", "--yaml yaml_file") { |x| opts["yaml"] = x }
21
21
  parser.on("--klass klass") { |x| opts["klass"] = x }
22
22
  end
@@ -25,7 +25,10 @@ dbconfig = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
25
25
  env = ENV.fetch("ENV", nil)
26
26
  env ||= "production"
27
27
 
28
- cli = Arxutils_Sqlite3::Cli.new(config, dbconfig, env)
28
+ acrecord = opts[:acrecord]
29
+ yaml_fname = opts["yaml"]
30
+ klass = opts["klass"]
31
+ cli = Arxutils_Sqlite3::Cli.new(config, dbconfig, env, acrecord, yaml_fname, klass)
29
32
 
30
33
  case opts["cmd"]
31
34
  when "s"
@@ -44,20 +47,16 @@ when "co"
44
47
  cli.copy_opts_file
45
48
 
46
49
  when "c"
47
- acrecord = opts[:acrecord]
48
- cli.makeconfig(acrecord, banner, 30, opts)
50
+ cli.makeconfig(opts)
49
51
 
50
52
  when "f"
51
- yaml_fname = opts["yaml"]
52
- acrecord = opts[:acrecord]
53
53
  if yaml_fname.nil? || yaml_fname.strip == ""
54
54
  puts banner
55
55
  exit 40
56
56
  end
57
57
  yaml_pn = Pathname.new(yaml_fname)
58
58
  config.check_file_not_exist(yaml_pn, banner, 55)
59
- cli.setup_for_migrate(yaml_pn, acrecord, klass)
60
-
59
+ cli.make_migrate_script
61
60
  when "m"
62
61
  cli.migrate
63
62
 
@@ -65,17 +64,17 @@ when "a"
65
64
  cli.acr
66
65
 
67
66
  when "d"
68
- db_scheme_ary = nil
69
- acrecord = opts["acrecord"]
70
- cli.delete(db_scheme_ary, acrecord)
67
+ cli.delete
71
68
 
72
69
  when "b"
73
- db_scheme_ary = nil
74
- acrecord = opts["acrecord"]
75
- cli.delete_db(db_scheme_ary, acrecord)
70
+ cli.delete_db
76
71
 
77
72
  when "y"
78
73
  cli.delete_setting_yaml
74
+
75
+ when "dm"
76
+ cli.delete_migrate
77
+
79
78
  else
80
79
  puts "Invalid command(#{opts["cmd"]}) specified!!"
81
80
  end
@@ -1,10 +1,23 @@
1
1
  module Arxutils_Sqlite3
2
2
  # CLI用クラス
3
3
  class Cli
4
- def initialize(config, dbconfig, env)
4
+ def initialize(config, dbconfig, env, acrecord, yaml_fname, klass)
5
5
  @config = config
6
6
  @dbconfig = dbconfig
7
7
  @env = env
8
+ @acrecord = acrecord
9
+ @dbconfig_path = @config.make_dbconfig_path(@dbconfig)
10
+
11
+ @db_scheme_ary = nil
12
+ if yaml_fname && yaml_fname.strip != ""
13
+ yaml_pn = Pathname.new(yaml_fname)
14
+ @db_scheme_ary = YAML.load_file(yaml_pn)
15
+ end
16
+ @mig = @config.prepare_for_migrate(@db_scheme_ary, @dbconfig_path, @dbconfig, @acrecord)
17
+ end
18
+
19
+ def setup_for_migrate(yaml_pn, klass)
20
+
8
21
  end
9
22
 
10
23
  def setup(klass)
@@ -29,24 +42,22 @@ module Arxutils_Sqlite3
29
42
  @config.copy_opts_file
30
43
  end
31
44
 
32
- def makeconfig(acrecord, _banner, _exit_code, opts)
45
+ def setup_for_migrate
33
46
  db_scheme_ary = nil
34
47
  dbconfig_path = @config.make_dbconfig_path(@dbconfig)
35
48
  # @config.check_file_exist(dbconfig_path, banner, exit_code)
36
- mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
37
- mig.make_dbconfig(opts)
49
+ @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, @acrecord)
38
50
  end
39
51
 
40
- def setup_for_migrate(yaml_pn, acrecord, klass)
41
- db_scheme_ary = YAML.load_file(yaml_pn)
42
- dbconfig_path = @config.make_dbconfig_path(@dbconfig)
43
-
44
- dest_dbsetup_file = @config.dest_dbsetup_file
45
- @config.make_dbsetup_file(db_scheme_ary, acrecord, klass, dest_dbsetup_file)
52
+ def makeconfig(opts)
53
+ @mig.make_dbconfig(opts)
54
+ end
46
55
 
56
+ def make_migrate_script
57
+ @dest_dbsetup_file = @config.dest_dbsetup_file
58
+ @config.make_dbsetup_file(@db_scheme_ary, @acrecord, @klass, @dest_dbsetup_file)
47
59
  # マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
48
- mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
49
- mig.output
60
+ @mig.output
50
61
  end
51
62
 
52
63
  # マイグレーション実行
@@ -75,25 +86,26 @@ module Arxutils_Sqlite3
75
86
  ret
76
87
  end
77
88
 
78
- def delete(db_scheme_ary, acrecord)
79
- config_dir = @config.config_dir
80
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, @dbconfig)
81
- mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
82
- mig.delete_migrate_and_config_and_db
89
+ def delete
90
+ @mig.delete_migrate_and_config_and_db
91
+ end
92
+
93
+ def delete_db
94
+ @mig.delete_db
83
95
  end
84
96
 
85
- def delete_db(db_scheme_ary, acrecord)
86
- config_dir = @config.config_dir
87
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, @dbconfig)
88
- mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
89
- # mig.delete_migrate_config_and_db
90
- mig.delete_db
97
+ def delete_nigrate
98
+ @mig.delete_migrate
91
99
  end
92
100
 
93
101
  def delete_setting_yaml
94
102
  FileUtils.rm_f(@config.setting_yaml_file)
95
103
  end
96
104
 
105
+ def delete_migrate
106
+ @mig.delete_migrate
107
+ end
108
+
97
109
  def rm_dbconfig
98
110
  dbconfig_path = @config.make_dbconfig_path(@dbconfig)
99
111
  # p dbconfig_path
@@ -85,7 +85,6 @@ module Arxutils_Sqlite3
85
85
  # DBファイルの削除
86
86
  def delete_db
87
87
  Dir.glob(File.join(@db_dir, "*")).each do |x|
88
- # puts x
89
88
  FileUtils.rm(x) if File.file?(x)
90
89
  end
91
90
  end
@@ -80,3 +80,8 @@ desc "delete setting yaml"
80
80
  task "arx:delete_setting" do
81
81
  sh "bundle exec arxutils_sqlite3 --cmd=y"
82
82
  end
83
+
84
+ desc "delete migrate scripts"
85
+ task "arx:delete_migrate" do
86
+ sh "bundle exec arxutils_sqlite3 --cmd=dm"
87
+ end
@@ -1,4 +1,4 @@
1
1
  module Arxutils_Sqlite3
2
2
  # バージョン番号
3
- VERSION = "0.1.54".freeze
3
+ VERSION = "0.1.56".freeze
4
4
  end
data/lib/dbacrecord.rb CHANGED
@@ -14,12 +14,12 @@ module Dbutil
14
14
  end
15
15
 
16
16
  class Invalidxenoplist < ActiveRecord::Base
17
- belongs_to :xenoplist, foreign_key: 'org_id'
18
- belongs_to :count, foreign_key: ''
17
+ belongs_to :xenoplist, foreign_key: "org_id"
18
+ belongs_to :count, foreign_key: ""
19
19
  end
20
20
 
21
21
  class Currentxenoplist < ActiveRecord::Base
22
- belongs_to :xenoplist , foreign_key: 'org_id'
22
+ belongs_to :xenoplist, foreign_key: "org_id"
23
23
  end
24
24
 
25
25
  end
@@ -1,3 +1,3 @@
1
1
  class Current<%= @data[:classname_downcase] %> < ActiveRecord::Base
2
- belongs_to :<%= @data[:classname_downcase] %> , foreign_key: 'org_id'
2
+ belongs_to :<%= @data[:classname_downcase] %>, foreign_key: "org_id"
3
3
  end
@@ -1,4 +1,4 @@
1
1
  class Invalid<%= @data[:classname_downcase] %> < ActiveRecord::Base
2
- belongs_to :<%= @data[:classname_downcase] %>, foreign_key: 'org_id'
3
- belongs_to :<%= @data[:count_classname_downcase] %>, foreign_key: '<%= @data[:count_field] %>'
2
+ belongs_to :<%= @data[:classname_downcase] %>, foreign_key: "org_id"
3
+ belongs_to :<%= @data[:count_classname_downcase] %>, foreign_key: "<%= @data[:count_field] %>"
4
4
  end
@@ -1,7 +1,7 @@
1
1
  class Create<%= @data[:classname] %> < ActiveRecord::Migration[<%= @data[:ar_version] %>]
2
2
  def self.up
3
3
  create_table :<%= @data[:plural] %> do |t|
4
- <% @data[:ary].each do |x| %>
4
+ <% @data[:ary].each do |x| %>
5
5
  t.column :<%= x.name %>, :<%= x.type %>, :null => <%= x.null %>
6
6
  <% end %>
7
7
  t.timestamps null: false
@@ -2,7 +2,7 @@ class CreateCurrent<%= @data[:classname_downcase] %> < ActiveRecord::Migration[<
2
2
  def self.up
3
3
  execute <<-SQL
4
4
  CREATE VIEW current<%= @data[:plural] %> AS SELECT id as org_id,
5
- <%= @data[:ary].map{|x| x.name }.join(" , ") %>
5
+ <%= @data[:ary].map{|x| x.name }.join(" , ") %>
6
6
  FROM <%= @data[:plural] %> where not exists (select * from invalid<%= @data[:plural] %> where invalid<%= @data[:plural] %>.org_id = <%= @data[:plural] %>.id )
7
7
  SQL
8
8
  end
@@ -1,9 +1,9 @@
1
- require_relative '../lib/dbacrecord'
1
+ require_relative "../lib/dbacrecord"
2
2
 
3
3
  class Dbsetup
4
4
  def initialize(connect_time)
5
5
  @connect_time = connect_time
6
- @ct = <%= klass %>::Dbutil::Countdatetime.create( countdatetime: @connect_time )
6
+ @ct = <%= klass %>::Dbutil::Countdatetime.create(countdatetime: @connect_time)
7
7
  @hs_by_notebook = {}
8
8
  @hs_by_id = {}
9
9
  end
@@ -1,9 +1,9 @@
1
1
  class Create<%= @data[:classname] %> < ActiveRecord::Migration[<%= @data[:ar_version] %>]
2
2
  def self.up
3
3
  create_table :<%= @data[:plural] %> do |t|
4
- <% @data[:ary].each do |x| %>
4
+ <% @data[:ary].each do |x| %>
5
5
  t.column :<%= x.name %>, :<%= x.type %>, :null => <%= x.null %>
6
- <% end %>
6
+ <% end %>
7
7
  end
8
8
  end
9
9
 
data/memo.md ADDED
@@ -0,0 +1,7 @@
1
+ ```mermaid
2
+ graph TD;
3
+ Cli#makeconfig-->config.prepare_for_migrate;
4
+ Cli#delete-->config.prepare_for_migrate;
5
+ Cli#delete_db-->config.prepare_for_migrate;
6
+ Cli#delete_migrate-->config.prepare_for_migrate;
7
+ ```
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arxutils_sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.54
4
+ version: 0.1.56
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasuo kominami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-23 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -243,6 +243,7 @@ files:
243
243
  - lib/template/acrecord/noitem.tmpl
244
244
  - lib/template/config/mysql.tmpl
245
245
  - lib/template/config/sqlite3.tmpl
246
+ - memo.md
246
247
  homepage: https://ykominami.github.io/arxutils_sqlite3/
247
248
  licenses:
248
249
  - MIT