jungle_path 0.0.20 → 0.0.21
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/jungle_path/db_access/io/db.rb +17 -0
- data/lib/jungle_path/db_access/meta.rb +10 -0
- data/lib/jungle_path/db_access/meta/db.rb +79 -0
- data/lib/jungle_path/db_access/meta/schema.rb +54 -0
- data/lib/jungle_path/db_access/meta/table.rb +26 -0
- data/lib/jungle_path/db_access/syntax.rb +9 -0
- data/lib/jungle_path/db_access/syntax/postgresql.rb +26 -0
- data/lib/jungle_path/db_access/syntax/sql_server.rb +26 -0
- data/lib/jungle_path/gen.rb +1 -0
- data/lib/jungle_path/version.rb +1 -1
- metadata +9 -4
- data/lib/jungle_path/gen/db.rb +0 -77
- data/lib/jungle_path/gen/schema.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee019b41cad42e01516a1c7310395b79037870ab
|
4
|
+
data.tar.gz: 86e255015d0974065a4b9e635389b04f4e4e4b34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b99ff226ab3a0e4046375e4993048d3ca6f6f371bb6cf639d862e77f3347adf998b0a9d44507ce80123372e0b9f7943f2823a7ba4ceaaf6e4f91c9620d003aa2
|
7
|
+
data.tar.gz: d7fa508186b220b18a387871f485c9f97fe0202117bd259d201e1a35c15a10523f963ff8df5d7b61417453b56676f9cca561e89b05489a215f8a88dd282b428c
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module JunglePath
|
2
2
|
module DBAccess
|
3
|
+
require 'jungle_path/db_access/meta/table'
|
3
4
|
module IO
|
4
5
|
require 'jungle_path/db_access/io'
|
5
6
|
require 'jungle_path/db_access/io/select'
|
@@ -45,6 +46,22 @@ module JunglePath
|
|
45
46
|
@database_name = config.name
|
46
47
|
end
|
47
48
|
|
49
|
+
def drop_table? table_name
|
50
|
+
JunglePath::DBAccess::Meta::Table.drop? self, table_name
|
51
|
+
end
|
52
|
+
|
53
|
+
def table_exists? table_name
|
54
|
+
JunglePath::DBAccess::Meta::Table.exists? self, table_name
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_table_like(from_table, to_table)
|
58
|
+
JunglePath::DBAccess::Meta::Table.create_like(self, from_table, to_table)
|
59
|
+
end
|
60
|
+
|
61
|
+
def copy_table_data(from_table, to_table)
|
62
|
+
JunglePath::DBAccess::Meta::Table.copy_data(self, from_table, to_table)
|
63
|
+
end
|
64
|
+
|
48
65
|
def reset_sequence_for_table(table_name)
|
49
66
|
#max = @db[table_name.to_sym].max(:id) + 1
|
50
67
|
#@db.run "alter sequence #{table_name}_id_seq restart with #{max}"
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# gen_db.rb -- drops and creates a postgresql database from the commandline dropdb/createdb commands.
|
2
|
+
require 'jungle_path/db_access/io'
|
3
|
+
|
4
|
+
module JunglePath
|
5
|
+
module DBAccess
|
6
|
+
module Meta
|
7
|
+
module DB
|
8
|
+
def self.create(config)
|
9
|
+
puts "JunglePath::DBAccess::Meta::DB.create: #{config.name}."
|
10
|
+
db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config)
|
11
|
+
sql = "create database #{config.name}"
|
12
|
+
db.run sql
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.drop!(config)
|
16
|
+
puts "JunglePath::DBAccess::Meta::DB.drop: #{config.name}."
|
17
|
+
kill_connections! config
|
18
|
+
db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config)
|
19
|
+
sql = "drop database #{config.name}"
|
20
|
+
db.run sql
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.drop?(config)
|
24
|
+
if exists?(config)
|
25
|
+
drop! config
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.reset!(config)
|
30
|
+
drop? config
|
31
|
+
create config
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.exists?(config) # todo: fix to also work for ms sql server.
|
35
|
+
puts "JunglePath::DBAccess::Meta::DB.exists? #{config.name}."
|
36
|
+
exists = false
|
37
|
+
db = JunglePath::DBAccess::IO.connection_from_config_unknown_database(config)
|
38
|
+
sql = sql_query_db_existence(config)
|
39
|
+
db.fetch(sql) do |row|
|
40
|
+
exists = true
|
41
|
+
end
|
42
|
+
exists
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.rename(config_from, to_name)
|
46
|
+
puts "JunglePath::DBAccess::Meta::DB.rename: #{config_from.name} to #{to_name}."
|
47
|
+
kill_connections! config_from
|
48
|
+
db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config_from)
|
49
|
+
sql = "alter database #{config_from.name} rename to #{to_name}"
|
50
|
+
db.run sql
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.rename?(config_from, to_name)
|
54
|
+
if exists?(config_from)
|
55
|
+
rename config_from, to_name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.kill_connections!(config)
|
60
|
+
db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config)
|
61
|
+
sql = "select pg_terminate_backend(pid) from pg_stat_activity where datname = '#{config.name}'"
|
62
|
+
db.run sql
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def self.sql_query_db_existence(config)
|
68
|
+
if config.type == 'postgres'
|
69
|
+
"select datname from pg_database where datname = '#{config.name}'"
|
70
|
+
elsif config.type == 'tinytds'
|
71
|
+
"select * from master.sys.databases where name = '#{config.name}'"
|
72
|
+
else
|
73
|
+
throw "Unknown database type: #{config.type}."
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# gen_schema.rb -- creates a database schema from a set of DBModel::Table (sub)classes.
|
2
|
+
require 'logger'
|
3
|
+
require 'sequel'
|
4
|
+
require 'jungle_path/db_model'
|
5
|
+
require 'jungle_path/db_access'
|
6
|
+
|
7
|
+
# todo: fix ! vs "" vs ? method calls...
|
8
|
+
module JunglePath
|
9
|
+
module DBAccess
|
10
|
+
module Meta
|
11
|
+
module Schema
|
12
|
+
def self.create(table_subclasses, db_config, logger=$stdout)
|
13
|
+
puts "JunglePath::DBAccess::Meta::Schema.create..."
|
14
|
+
db = JunglePath::DBAccess::IO.connection_from_config(db_config)
|
15
|
+
db.loggers << Logger.new(logger)
|
16
|
+
schema = JunglePath::DBModel::Schema.new(db)
|
17
|
+
table_subclasses.each do |table|
|
18
|
+
if table.is_view?
|
19
|
+
puts "create view: #{table.table_name}"
|
20
|
+
db.run(table.view.create)
|
21
|
+
else
|
22
|
+
puts "create table: #{table.table_name}"
|
23
|
+
schema.create_table table
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.set_version schema_info_class, db_config, schema_initial_version
|
29
|
+
# set starting version numnber
|
30
|
+
db = JunglePath::DBAccess::IO::DB.new(db_config)
|
31
|
+
db.schema.create_table schema_info_class
|
32
|
+
if schema_initial_version
|
33
|
+
schema_info = schema_info_class.new({version: schema_initial_version})
|
34
|
+
db.insert._model(schema_info)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.set_version_to_latest schema_info_class, db_config, migrations_path
|
39
|
+
version = 0
|
40
|
+
migration_files = Dir.glob(File.join(migrations_path, "*.rb"))
|
41
|
+
migration_files.each do |file_name|
|
42
|
+
puts file_name
|
43
|
+
parts = File.basename(file_name).split('_')
|
44
|
+
if parts.length > 0
|
45
|
+
value = parts[0].to_i
|
46
|
+
version = value if value > version
|
47
|
+
end
|
48
|
+
end
|
49
|
+
set_version schema_info_class, db_config, version
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# table manipulation.
|
2
|
+
# db.base is a Sequel database object.
|
3
|
+
# db is can be a JunglePath::DBAccess::IO::DB object.
|
4
|
+
module JunglePath
|
5
|
+
module DBAccess
|
6
|
+
module Meta
|
7
|
+
module Table
|
8
|
+
def drop? db, table_name
|
9
|
+
db.base.drop_table?(table_name.to_sym)
|
10
|
+
end
|
11
|
+
|
12
|
+
def exists? db, table_name
|
13
|
+
db.base.table_exists?(table_name.to_sym)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_like(db, from_table, to_table)
|
17
|
+
db.base.run("create table #{to_table} (like #{from_table} including indexes)")
|
18
|
+
end
|
19
|
+
|
20
|
+
def copy_data(db, from_table, to_table)
|
21
|
+
db.base.run("insert into #{to_table} select * from #{from_table}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module JunglePath
|
2
|
+
module DBAccess
|
3
|
+
module Syntax
|
4
|
+
module Postgresql
|
5
|
+
def self.sql_true
|
6
|
+
"true"
|
7
|
+
end
|
8
|
+
def self.sql_allow_order_bys_in_sub_select
|
9
|
+
""
|
10
|
+
end
|
11
|
+
def self.left_bracket
|
12
|
+
""
|
13
|
+
end
|
14
|
+
def self.right_bracket
|
15
|
+
""
|
16
|
+
end
|
17
|
+
def self.convert_nvarchar_beg
|
18
|
+
""
|
19
|
+
end
|
20
|
+
def self.convert_nvarchar_end
|
21
|
+
"::text"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module JunglePath
|
2
|
+
module DBAccess
|
3
|
+
module Syntax
|
4
|
+
module SqlServer
|
5
|
+
def self.sql_true
|
6
|
+
"1"
|
7
|
+
end
|
8
|
+
def self.sql_allow_order_bys_in_sub_select
|
9
|
+
"top 1000000000"
|
10
|
+
end
|
11
|
+
def self.left_bracket
|
12
|
+
"["
|
13
|
+
end
|
14
|
+
def self.right_bracket
|
15
|
+
"]"
|
16
|
+
end
|
17
|
+
def self.convert_nvarchar_beg
|
18
|
+
"convert(nvarchar, "
|
19
|
+
end
|
20
|
+
def self.convert_nvarchar_end
|
21
|
+
")"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/jungle_path/gen.rb
CHANGED
data/lib/jungle_path/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jungle_path
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael VanZant
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,6 +135,13 @@ files:
|
|
135
135
|
- lib/jungle_path/db_access/io/schema.rb
|
136
136
|
- lib/jungle_path/db_access/io/select.rb
|
137
137
|
- lib/jungle_path/db_access/io/update.rb
|
138
|
+
- lib/jungle_path/db_access/meta.rb
|
139
|
+
- lib/jungle_path/db_access/meta/db.rb
|
140
|
+
- lib/jungle_path/db_access/meta/schema.rb
|
141
|
+
- lib/jungle_path/db_access/meta/table.rb
|
142
|
+
- lib/jungle_path/db_access/syntax.rb
|
143
|
+
- lib/jungle_path/db_access/syntax/postgresql.rb
|
144
|
+
- lib/jungle_path/db_access/syntax/sql_server.rb
|
138
145
|
- lib/jungle_path/db_model.rb
|
139
146
|
- lib/jungle_path/db_model/column.rb
|
140
147
|
- lib/jungle_path/db_model/params.rb
|
@@ -149,8 +156,6 @@ files:
|
|
149
156
|
- lib/jungle_path/gen.rb
|
150
157
|
- lib/jungle_path/gen/api.rb
|
151
158
|
- lib/jungle_path/gen/controllers.rb
|
152
|
-
- lib/jungle_path/gen/db.rb
|
153
|
-
- lib/jungle_path/gen/schema.rb
|
154
159
|
- lib/jungle_path/gen/schema_tree.rb
|
155
160
|
- lib/jungle_path/gen/schema_tree/filter.rb
|
156
161
|
- lib/jungle_path/gen/schema_tree/match_columns.rb
|
data/lib/jungle_path/gen/db.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# gen_db.rb -- drops and creates a postgresql database from the commandline dropdb/createdb commands.
|
2
|
-
require 'jungle_path/db_access/io'
|
3
|
-
|
4
|
-
module JunglePath
|
5
|
-
module Gen
|
6
|
-
module DB
|
7
|
-
def self.create(config)
|
8
|
-
puts "Gen::DB.create: #{config.name}."
|
9
|
-
db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config)
|
10
|
-
sql = "create database #{config.name}"
|
11
|
-
db.run sql
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.drop!(config)
|
15
|
-
puts "Gen::DB.drop: #{config.name}."
|
16
|
-
kill_connections! config
|
17
|
-
db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config)
|
18
|
-
sql = "drop database #{config.name}"
|
19
|
-
db.run sql
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.drop?(config)
|
23
|
-
if exists?(config)
|
24
|
-
drop! config
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.reset!(config)
|
29
|
-
drop? config
|
30
|
-
create config
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.exists?(config) # todo: fix to also work for ms sql server.
|
34
|
-
puts "Gen::DB.exists? #{config.name}."
|
35
|
-
exists = false
|
36
|
-
db = JunglePath::DBAccess::IO.connection_from_config_unknown_database(config)
|
37
|
-
sql = sql_query_db_existence(config)
|
38
|
-
db.fetch(sql) do |row|
|
39
|
-
exists = true
|
40
|
-
end
|
41
|
-
exists
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.rename(config_from, to_name)
|
45
|
-
puts "GenDB.rename: #{config_from.name} to #{to_name}."
|
46
|
-
kill_connections! config_from
|
47
|
-
db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config_from)
|
48
|
-
sql = "alter database #{config_from.name} rename to #{to_name}"
|
49
|
-
db.run sql
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.rename?(config_from, to_name)
|
53
|
-
if exists?(config_from)
|
54
|
-
rename config_from, to_name
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.kill_connections!(config)
|
59
|
-
db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config)
|
60
|
-
sql = "select pg_terminate_backend(pid) from pg_stat_activity where datname = '#{config.name}'"
|
61
|
-
db.run sql
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def self.sql_query_db_existence(config)
|
67
|
-
if config.type == 'postgres'
|
68
|
-
"select datname from pg_database where datname = '#{config.name}'"
|
69
|
-
elsif config.type == 'tinytds'
|
70
|
-
"select * from master.sys.databases where name = '#{config.name}'"
|
71
|
-
else
|
72
|
-
throw "Unknown database type: #{config.type}."
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# gen_schema.rb -- creates a database schema from a set of DBModel::Table (sub)classes.
|
2
|
-
require 'logger'
|
3
|
-
require 'sequel'
|
4
|
-
require 'jungle_path/db_model'
|
5
|
-
require 'jungle_path/db_access'
|
6
|
-
|
7
|
-
# todo: fix ! vs "" vs ? method calls...
|
8
|
-
module JunglePath
|
9
|
-
module Gen
|
10
|
-
module Schema
|
11
|
-
def self.create(table_subclasses, db_config, logger=$stdout)
|
12
|
-
puts "Gen::Schema.create..."
|
13
|
-
db = JunglePath::DBAccess::IO.connection_from_config(db_config)
|
14
|
-
db.loggers << Logger.new(logger)
|
15
|
-
schema = JunglePath::DBModel::Schema.new(db)
|
16
|
-
table_subclasses.each do |table|
|
17
|
-
if table.is_view?
|
18
|
-
puts "create view: #{table.table_name}"
|
19
|
-
db.run(table.view.create)
|
20
|
-
else
|
21
|
-
puts "create table: #{table.table_name}"
|
22
|
-
schema.create_table table
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.set_version schema_info_class, db_config, schema_initial_version
|
28
|
-
# set starting version numnber
|
29
|
-
db = JunglePath::DBAccess::IO::DB.new(db_config)
|
30
|
-
db.schema.create_table schema_info_class
|
31
|
-
if schema_initial_version
|
32
|
-
schema_info = schema_info_class.new({version: schema_initial_version})
|
33
|
-
db.insert._model(schema_info)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.set_version_to_latest schema_info_class, db_config, migrations_path
|
38
|
-
version = 0
|
39
|
-
migration_files = Dir.glob(File.join(migrations_path, "*.rb"))
|
40
|
-
migration_files.each do |file_name|
|
41
|
-
puts file_name
|
42
|
-
parts = File.basename(file_name).split('_')
|
43
|
-
if parts.length > 0
|
44
|
-
value = parts[0].to_i
|
45
|
-
version = value if value > version
|
46
|
-
end
|
47
|
-
end
|
48
|
-
set_version schema_info_class, db_config, version
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|