prick 0.4.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/TODO +7 -0
- data/exe/prick +235 -163
- data/lib/ext/fileutils.rb +7 -0
- data/lib/prick.rb +7 -5
- data/lib/prick/builder.rb +31 -8
- data/lib/prick/cache.rb +34 -0
- data/lib/prick/constants.rb +106 -54
- data/lib/prick/database.rb +26 -20
- data/lib/prick/diff.rb +103 -25
- data/lib/prick/git.rb +31 -9
- data/lib/prick/head.rb +183 -0
- data/lib/prick/migration.rb +41 -181
- data/lib/prick/program.rb +255 -0
- data/lib/prick/project.rb +274 -0
- data/lib/prick/rdbms.rb +3 -12
- data/lib/prick/schema.rb +7 -11
- data/lib/prick/state.rb +129 -74
- data/lib/prick/version.rb +41 -28
- data/prick.gemspec +3 -1
- data/share/diff/diff.after-tables.sql +4 -0
- data/share/diff/diff.before-tables.sql +4 -0
- data/share/diff/diff.tables.sql +8 -0
- data/share/migration/diff.tables.sql +8 -0
- data/share/{release_migration → migration}/features.yml +0 -0
- data/share/migration/migrate.sql +3 -0
- data/share/{release_migration → migration}/migrate.yml +3 -0
- data/share/migration/tables.sql +3 -0
- data/share/{schemas → schema/schema}/build.yml +0 -0
- data/share/{schemas → schema/schema}/prick/build.yml +0 -0
- data/share/schema/schema/prick/data.sql +7 -0
- data/share/{schemas → schema/schema}/prick/schema.sql +0 -0
- data/share/{schemas → schema/schema}/prick/tables.sql +2 -2
- data/share/{schemas → schema/schema}/public/.keep +0 -0
- data/share/{schemas → schema/schema}/public/build.yml +0 -0
- data/share/{schemas → schema/schema}/public/schema.sql +0 -0
- data/test_refactor +34 -0
- metadata +23 -21
- data/file +0 -0
- data/lib/prick/build.rb +0 -376
- data/lib/prick/migra.rb +0 -22
- data/share/feature_migration/diff.sql +0 -2
- data/share/feature_migration/migrate.sql +0 -2
- data/share/release_migration/diff.sql +0 -3
- data/share/release_migration/migrate.sql +0 -5
- data/share/schemas/prick/data.sql +0 -7
data/lib/ext/fileutils.rb
CHANGED
@@ -7,6 +7,7 @@ module FileUtils
|
|
7
7
|
dir = File.dirname(file)
|
8
8
|
File.exist?(dir) or FileUtils.mkdir_p(dir)
|
9
9
|
touch(file)
|
10
|
+
file
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.ln_sr(from, to)
|
@@ -16,4 +17,10 @@ module FileUtils
|
|
16
17
|
relpath = from.relative_path_from(File.dirname(to))
|
17
18
|
Dir.chdir(to_dir) { FileUtils.ln_s(relpath, File.basename(to)) }
|
18
19
|
end
|
20
|
+
|
21
|
+
def self.empty!(dir)
|
22
|
+
Dir.chdir(dir) {
|
23
|
+
FileUtils.rm_rf(Dir.children("."))
|
24
|
+
}
|
25
|
+
end
|
19
26
|
end
|
data/lib/prick.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
#$LOAD_PATH.unshift("/home/clr/prj/shellopts/lib")
|
3
|
+
|
4
|
+
# 'semantic' is required here instead of in prick/version.rb to avoid having Gem depend on it
|
5
|
+
require "semantic"
|
2
6
|
|
3
7
|
# Needs to go first because it contains class-level methods that is used by other modules
|
4
8
|
require "ext/forward_method.rb"
|
5
9
|
|
6
|
-
require "prick/branch.rb"
|
7
10
|
require "prick/builder.rb"
|
8
11
|
require "prick/migration.rb"
|
12
|
+
require "prick/cache.rb"
|
9
13
|
require "prick/command.rb"
|
10
14
|
require "prick/constants.rb"
|
11
15
|
require "prick/database.rb"
|
12
16
|
require "prick/diff.rb"
|
13
17
|
require "prick/exceptions.rb"
|
14
18
|
require "prick/git.rb"
|
19
|
+
require "prick/head.rb"
|
15
20
|
require "prick/project.rb"
|
16
21
|
require "prick/rdbms.rb"
|
17
22
|
require "prick/schema.rb"
|
@@ -22,8 +27,5 @@ require "prick/version.rb"
|
|
22
27
|
require "ext/fileutils.rb"
|
23
28
|
require "ext/shortest_path.rb"
|
24
29
|
|
25
|
-
require "indented_io"
|
26
|
-
|
27
30
|
module Prick
|
28
31
|
end
|
29
|
-
|
data/lib/prick/builder.rb
CHANGED
@@ -24,14 +24,19 @@ module Prick
|
|
24
24
|
attr_reader :database
|
25
25
|
attr_reader :directory
|
26
26
|
attr_reader :default # either "build" or "migrate"
|
27
|
+
attr_reader :lines
|
27
28
|
|
28
29
|
def initialize(database, directory, default)
|
29
30
|
@database = database
|
30
31
|
@directory = directory
|
31
32
|
@default = default
|
33
|
+
@execute = true
|
34
|
+
@lines = []
|
32
35
|
end
|
33
36
|
|
34
|
-
def build(subject =
|
37
|
+
def build(subject = default, execute: true)
|
38
|
+
@execute = execute
|
39
|
+
@lines = []
|
35
40
|
# puts "Building #{subject.inspect}"
|
36
41
|
Dir.chdir(directory) {
|
37
42
|
if subject
|
@@ -40,6 +45,8 @@ module Prick
|
|
40
45
|
build_directory(".")
|
41
46
|
end
|
42
47
|
}
|
48
|
+
@lines.reject! { |l| l =~ /^\s*--/ || l =~ /^\s*$/ }
|
49
|
+
self
|
43
50
|
end
|
44
51
|
|
45
52
|
def self.yml_file(directory) raise NotThis end
|
@@ -52,13 +59,26 @@ module Prick
|
|
52
59
|
|
53
60
|
def do_sql(path)
|
54
61
|
# puts "do_sql(#{path})"
|
55
|
-
do_dir(path) { |file|
|
62
|
+
do_dir(path) { |file|
|
63
|
+
if @execute
|
64
|
+
Rdbms.exec_file(database.name, file, user: database.user)
|
65
|
+
else
|
66
|
+
@lines += IO.readlines(file).map(&:chomp)
|
67
|
+
end
|
68
|
+
}
|
56
69
|
true
|
57
70
|
end
|
58
71
|
|
59
72
|
def do_exe(path)
|
60
73
|
# puts "do_exe(#{path})"
|
61
|
-
do_dir(path) { |file|
|
74
|
+
do_dir(path) { |file|
|
75
|
+
lines = Command.command "#{file} #{database.name} #{database.user}" # FIXME Security
|
76
|
+
if @execute
|
77
|
+
Rdbms.exec_sql(database.name, lines.join("\n"), database.user)
|
78
|
+
else
|
79
|
+
@lines += lines
|
80
|
+
end
|
81
|
+
}
|
62
82
|
true
|
63
83
|
end
|
64
84
|
|
@@ -73,9 +93,9 @@ module Prick
|
|
73
93
|
def build_subject(subject)
|
74
94
|
if File.file?(subject) && File.executable?(subject)
|
75
95
|
do_exe(subject)
|
76
|
-
elsif subject.end_with?(".yml")
|
96
|
+
elsif File.file?(subject) && subject.end_with?(".yml")
|
77
97
|
do_yml(subject)
|
78
|
-
elsif subject.end_with?(".sql")
|
98
|
+
elsif File.file?(subject) && subject.end_with?(".sql")
|
79
99
|
do_sql(subject)
|
80
100
|
elsif File.exist?(yml_file = "#{subject}.yml")
|
81
101
|
do_yml(yml_file)
|
@@ -90,7 +110,7 @@ module Prick
|
|
90
110
|
|
91
111
|
def build_directory(path)
|
92
112
|
Dir.chdir(path) {
|
93
|
-
build_subject(File.join(path,
|
113
|
+
build_subject(File.join(path, @default)) || begin
|
94
114
|
if Dir["#{path}/#{default}", "#{path}/#{default}.yml", "#{path}/#{default}.sql"]
|
95
115
|
subjects = [default]
|
96
116
|
else
|
@@ -119,8 +139,10 @@ module Prick
|
|
119
139
|
super(database, directory, "build")
|
120
140
|
end
|
121
141
|
|
122
|
-
def build(subject = nil)
|
142
|
+
def build(subject = nil, execute: true)
|
123
143
|
if subject
|
144
|
+
@execute = execute
|
145
|
+
@lines = []
|
124
146
|
Dir.chdir(directory) {
|
125
147
|
if File.executable?(subject)
|
126
148
|
do_exe(subject)
|
@@ -131,8 +153,9 @@ module Prick
|
|
131
153
|
end
|
132
154
|
}
|
133
155
|
else
|
134
|
-
super()
|
156
|
+
super(execute: execute)
|
135
157
|
end
|
158
|
+
self
|
136
159
|
end
|
137
160
|
|
138
161
|
def self.yml_file(directory) File.join(directory, "build") + ".yml" end
|
data/lib/prick/cache.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
module Prick
|
3
|
+
class Cache
|
4
|
+
def initialize
|
5
|
+
end
|
6
|
+
|
7
|
+
def exist?(version)
|
8
|
+
File.exist?(file(version))
|
9
|
+
end
|
10
|
+
|
11
|
+
def list
|
12
|
+
Dir.glob(File.join(CACHE_DIR, "*.sql.gz"))
|
13
|
+
end
|
14
|
+
|
15
|
+
def load(database, version)
|
16
|
+
Rdbms.load(database, file(version))
|
17
|
+
end
|
18
|
+
|
19
|
+
def save(database, version = database.version)
|
20
|
+
Rdbms.save(database, file(version))
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns list of removed files
|
24
|
+
def clean
|
25
|
+
l = list
|
26
|
+
FileUtils.rm(l)
|
27
|
+
l
|
28
|
+
end
|
29
|
+
|
30
|
+
def file(version)
|
31
|
+
File.join(CACHE_DIR, "#{version}.sql.gz")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/prick/constants.rb
CHANGED
@@ -2,31 +2,16 @@
|
|
2
2
|
module Prick
|
3
3
|
### DIRECTORIES AND FILE NAMES
|
4
4
|
|
5
|
-
# Path to the .prick-version file
|
6
|
-
PRICK_VERSION_FILE = ".prick-version"
|
7
|
-
|
8
|
-
# State files
|
9
|
-
PROJECT_STATE_FILE = ".prick-project"
|
10
|
-
FEATURES_STATE_FILE = ".prick-features"
|
11
|
-
MIGRATION_STATE_FILE = ".prick-migration"
|
12
|
-
MIGRATIONS_FILE = "migrations.sql"
|
13
|
-
|
14
|
-
# Diff file
|
15
|
-
DIFF_FILE = "diff.sql"
|
16
|
-
|
17
5
|
# Shared files (part of the installation)
|
18
6
|
SHARE_PATH = "#{File.dirname(File.dirname(__dir__))}/share"
|
19
7
|
LIBEXEC_PATH = "#{File.dirname(File.dirname(__dir__))}/libexec"
|
20
8
|
|
21
|
-
STRIP_COMMENTS_COMMAND = File.join(LIBEXEC_PATH, "strip-comments")
|
22
|
-
|
23
9
|
# Project directories
|
24
10
|
DIRS = [
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
PUBLIC_DIR = "#{SCHEMAS_DIR}/public",
|
11
|
+
MIGRATION_DIR = "migration",
|
12
|
+
SCHEMA_DIR = "schema",
|
13
|
+
PRICK_DIR = "#{SCHEMA_DIR}/prick",
|
14
|
+
PUBLIC_DIR = "#{SCHEMA_DIR}/public",
|
30
15
|
VAR_DIR = "var",
|
31
16
|
CACHE_DIR = "#{VAR_DIR}/cache",
|
32
17
|
SPOOL_DIR = "#{VAR_DIR}/spool",
|
@@ -35,9 +20,42 @@ module Prick
|
|
35
20
|
SPEC_DIR = "spec"
|
36
21
|
]
|
37
22
|
|
38
|
-
#
|
39
|
-
|
40
|
-
|
23
|
+
# The project state file
|
24
|
+
PROJECT_STATE_FILE = ".prick-project"
|
25
|
+
PROJECT_STATE_PATH = PROJECT_STATE_FILE
|
26
|
+
|
27
|
+
# The .prick-version file
|
28
|
+
PRICK_VERSION_FILE = ".prick-version"
|
29
|
+
PRICK_VERSION_PATH = PRICK_VERSION_FILE
|
30
|
+
|
31
|
+
# The prick.versions data file. This is where the Schema saves its version
|
32
|
+
SCHEMA_VERSION_FILE = "data.sql"
|
33
|
+
SCHEMA_VERSION_PATH = File.join(PRICK_DIR, SCHEMA_VERSION_FILE)
|
34
|
+
|
35
|
+
# The the .prick-migration file
|
36
|
+
PRICK_MIGRATION_FILE = ".prick-migration"
|
37
|
+
PRICK_MIGRATION_PATH = File.join(MIGRATION_DIR, PRICK_MIGRATION_FILE)
|
38
|
+
|
39
|
+
# The the .prick-feature file
|
40
|
+
PRICK_FEATURE_FILE = ".prick-feature"
|
41
|
+
PRICK_FEATURE_PATH = File.join(MIGRATION_DIR, PRICK_FEATURE_FILE)
|
42
|
+
|
43
|
+
# The strip-comments executable
|
44
|
+
STRIP_COMMENTS_NAME = "strip-comments"
|
45
|
+
STRIP_COMMENTS_PATH = File.join(LIBEXEC_PATH, "strip-comments")
|
46
|
+
|
47
|
+
# Diff files
|
48
|
+
DIFF_FILE = "diff.sql"
|
49
|
+
BEFORE_TABLES_DIFF_NAME = "diff.before-tables.sql"
|
50
|
+
TABLES_DIFF_NAME = "diff.tables.sql"
|
51
|
+
AFTER_TABLES_DIFF_NAME = "diff.after-tables.sql"
|
52
|
+
|
53
|
+
BEFORE_TABLES_DIFF_PATH = File.join(MIGRATION_DIR, BEFORE_TABLES_DIFF_NAME)
|
54
|
+
TABLES_DIFF_PATH = File.join(MIGRATION_DIR, TABLES_DIFF_NAME)
|
55
|
+
AFTER_TABLES_DIFF_PATH = File.join(MIGRATION_DIR, AFTER_TABLES_DIFF_NAME)
|
56
|
+
|
57
|
+
TABLES_DIFF_SHARE_PATH = File.join(SHARE_PATH, "diff", TABLES_DIFF_NAME)
|
58
|
+
|
41
59
|
|
42
60
|
# Dump files
|
43
61
|
DUMP_EXT = "dump.gz"
|
@@ -46,33 +64,27 @@ module Prick
|
|
46
64
|
|
47
65
|
### REGULAR EXPRESSIONS
|
48
66
|
|
67
|
+
# Matches a system name. System names are used for objects that are external to prick
|
68
|
+
# (like usernames)
|
69
|
+
NAME_SUB_RE = /[a-z][a-z0-9_-]*/
|
70
|
+
NAME_RE = /^#{NAME_SUB_RE}$/
|
71
|
+
|
49
72
|
# Matches an identifier. Identifiers consist of lower case letters, digits
|
50
73
|
# and underscores but not dashes because they're used as separators
|
51
74
|
IDENT_SUB_RE = /[a-z][a-z0-9_]*/
|
52
75
|
IDENT_RE = /^#{IDENT_SUB_RE}$/
|
53
76
|
|
54
|
-
# Matches an uppercase identifier
|
55
|
-
# UPCASE_IDENT_SUB_RE = /[A-Z][A-Z0-9_]*/
|
56
|
-
# UPCASE_IDENT_RE = /#{UPCASE_IDENT_SUB_RE}/
|
57
|
-
|
58
|
-
# A (system) name. Names are used for projects and usernames that are
|
59
|
-
# external to prick and can include both dashes and underscores but dashes
|
60
|
-
# have to be followed by a character and not a digit so 'ident-1234' is not
|
61
|
-
# allowed but 'ident_1234' and 'ident1234' are
|
62
|
-
NAME_SUB_RE = /#{IDENT_SUB_RE}/
|
63
|
-
NAME_RE = /^#{NAME_SUB_RE}$/
|
64
|
-
|
65
77
|
# Matches a project name
|
66
|
-
PROJECT_NAME_SUB_RE =
|
67
|
-
PROJECT_NAME_RE =
|
78
|
+
PROJECT_NAME_SUB_RE = IDENT_SUB_RE
|
79
|
+
PROJECT_NAME_RE = IDENT_RE
|
68
80
|
|
69
81
|
# Matches a custom name
|
70
|
-
CUSTOM_NAME_SUB_RE =
|
71
|
-
CUSTOM_NAME_RE =
|
82
|
+
CUSTOM_NAME_SUB_RE = IDENT_SUB_RE
|
83
|
+
CUSTOM_NAME_RE = IDENT_RE
|
72
84
|
|
73
85
|
# Matches a feature name
|
74
|
-
FEATURE_NAME_SUB_RE =
|
75
|
-
FEATURE_NAME_RE =
|
86
|
+
FEATURE_NAME_SUB_RE = /(?!initial)#{IDENT_SUB_RE}/
|
87
|
+
FEATURE_NAME_RE = /^#{FEATURE_NAME_SUB_RE}$/
|
76
88
|
|
77
89
|
# Matches a postgres user name
|
78
90
|
USER_NAME_SUB_RE = NAME_SUB_RE
|
@@ -103,15 +115,48 @@ module Prick
|
|
103
115
|
SEMVER_SUB_RE = /#{MMP_SEMVER_SUB_RE}(?:-#{PRE_SEMVER_SUB_RE})?/
|
104
116
|
SEMVER_RE = /^#{SEMVER_SUB_RE}$/
|
105
117
|
|
106
|
-
#
|
118
|
+
# Tag RE. The general syntax for a tag is '<custom>-v<version>_<feature>'
|
119
|
+
#
|
120
|
+
# The RE defines the following captures:
|
121
|
+
# $1 - custom name, can be nil
|
122
|
+
# $2 - semantic version
|
123
|
+
# $3 - feature name, can be nil
|
124
|
+
#
|
125
|
+
TAG_SUB_RE = /
|
126
|
+
(?:(#{CUSTOM_NAME_SUB_RE})-)?
|
127
|
+
v
|
128
|
+
(#{SEMVER_SUB_RE})
|
129
|
+
(?:_(#{FEATURE_NAME_SUB_RE}))?
|
130
|
+
/x
|
131
|
+
TAG_RE = /^#{TAG_SUB_RE}$/
|
132
|
+
|
133
|
+
# TODO: Handle initial branches (0.0.0-initial)
|
134
|
+
|
135
|
+
# Branch RE. The general syntax for a branch is '<custom>-<version>_<feature>'
|
107
136
|
#
|
108
137
|
# The RE defines the following captures:
|
109
138
|
# $1 - custom name, can be nil
|
110
139
|
# $2 - semantic version
|
111
140
|
# $3 - feature name, can be nil
|
112
141
|
#
|
142
|
+
BRANCH_SUB_RE = /
|
143
|
+
(?:(#{CUSTOM_NAME_SUB_RE})-)?
|
144
|
+
(#{SEMVER_SUB_RE})
|
145
|
+
(?:_(#{FEATURE_NAME_SUB_RE}))?
|
146
|
+
/x
|
147
|
+
BRANCH_RE = /^#{BRANCH_SUB_RE}$/
|
148
|
+
|
149
|
+
# Tag or branch RE. The general syntax for a branch is '<custom>-v?<version>_<feature>'
|
150
|
+
#
|
151
|
+
# The RE defines the following captures:
|
152
|
+
# $1 - custom name, can be nil
|
153
|
+
# $2 - tag, nil or 'v'
|
154
|
+
# $3 - semantic version
|
155
|
+
# $4 - feature name, can be nil
|
156
|
+
#
|
113
157
|
VERSION_SUB_RE = /
|
114
158
|
(?:(#{CUSTOM_NAME_SUB_RE})-)?
|
159
|
+
(v)?
|
115
160
|
(#{SEMVER_SUB_RE})
|
116
161
|
(?:_(#{FEATURE_NAME_SUB_RE}))?
|
117
162
|
/x
|
@@ -135,11 +180,11 @@ module Prick
|
|
135
180
|
# $1 - custom name, can be nil
|
136
181
|
# $2 - semantic version
|
137
182
|
#
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
183
|
+
# RELEASE_SUB_RE = /
|
184
|
+
# (?:(#{CUSTOM_NAME_SUB_RE})-)?
|
185
|
+
# (#{MMP_SEMVER_SUB_RE})
|
186
|
+
# /x
|
187
|
+
# RELEASE_RE = /^#{RELEASE_SUB_RE}$/
|
143
188
|
|
144
189
|
# Matches a prerelease branch
|
145
190
|
#
|
@@ -147,11 +192,11 @@ module Prick
|
|
147
192
|
# $1 - custom name, can be nil
|
148
193
|
# $2 - semantic version
|
149
194
|
#
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
195
|
+
# PRERELEASE_SUB_RE = /
|
196
|
+
# (?:(#{CUSTOM_NAME_SUB_RE})-)?
|
197
|
+
# (#{MMP_SEMVER_SUB_RE}-#{PRE_SEMVER_SUB_RE})
|
198
|
+
# /x
|
199
|
+
# PRERELEASE_RE = /^#{PRERELEASE_SUB_RE}$/
|
155
200
|
|
156
201
|
# Matches a feature branch
|
157
202
|
#
|
@@ -160,8 +205,8 @@ module Prick
|
|
160
205
|
# $2 - semantic version
|
161
206
|
# $3 - feature name
|
162
207
|
#
|
163
|
-
|
164
|
-
|
208
|
+
# FEATURE_SUB_RE = /#{ABSTRACT_RELEASE_SUB_RE}_(#{FEATURE_NAME_SUB_RE})/
|
209
|
+
# FEATURE_RE = /^#{FEATURE_SUB_RE}$/
|
165
210
|
|
166
211
|
# Migration RE. The syntax is <version>_<version>
|
167
212
|
#
|
@@ -173,8 +218,8 @@ module Prick
|
|
173
218
|
# $5 - to custom name, can be nil
|
174
219
|
# $6 - to semantic version
|
175
220
|
#
|
176
|
-
|
177
|
-
|
221
|
+
# MIGRATION_SUB_RE = /(#{RELEASE_SUB_RE})_(#{RELEASE_SUB_RE})/
|
222
|
+
# MIGRATION_RE = /^#{MIGRATION_SUB_RE}$/
|
178
223
|
|
179
224
|
# Project release RE. The general syntax is '<project>-<custom>-<version>'
|
180
225
|
#
|
@@ -217,5 +262,12 @@ module Prick
|
|
217
262
|
ALL_DATABASES_RE = /^#{ALL_DATABASES_SUB_RE}$/
|
218
263
|
def self.all_databases_sub_re(project_name) /(#{project_name})(?:-(#{ABSTRACT_RELEASE_SUB_RE}))?/ end
|
219
264
|
def self.all_databases_re(project_name) /^#{all_databases_sub_re(project_name)}$/ end
|
265
|
+
|
266
|
+
# Matches temporary databases. Mostly useful when debugging because temporary databases
|
267
|
+
# should be deleted on exit
|
268
|
+
TMP_DATABASES_SUB_RE = /#{PROJECT_NAME_SUB_RE}-(?:base|next)/
|
269
|
+
TMP_DATABASES_RE = /^#{TMP_DATABASES_SUB_RE}$/
|
270
|
+
def self.tmp_databases_sub_re(project_name) /#{project_name}-(?:base|next)/ end
|
271
|
+
def self.tmp_databases_re(project_name) /^#{tmp_databases_sub_re(project_name)}$/ end
|
220
272
|
end
|
221
273
|
|
data/lib/prick/database.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
|
2
|
-
#require "prick/ensure.rb"
|
3
|
-
|
4
2
|
module Prick
|
5
3
|
class Database
|
6
4
|
attr_reader :name
|
7
5
|
attr_reader :user
|
8
6
|
|
9
7
|
def initialize(name, user)
|
8
|
+
name != "" or raise "Illegal database name"
|
10
9
|
@name = name
|
11
10
|
@user = user
|
12
11
|
@version = nil
|
13
12
|
end
|
14
13
|
|
15
|
-
def version
|
16
|
-
@version
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
def version(cache: true)
|
15
|
+
if cache && @version
|
16
|
+
@version
|
17
|
+
else
|
18
|
+
@version = begin
|
19
|
+
version =
|
20
|
+
if exist? && Rdbms.exist_table?(name, "prick", "versions")
|
21
|
+
Rdbms.select(name, "select version from prick.versions")&.first&.first
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
version && Version.new(version)
|
26
|
+
end
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
@@ -43,18 +46,21 @@ module Prick
|
|
43
46
|
def drop() Rdbms.drop_database(name, fail: false); @version = nil end
|
44
47
|
|
45
48
|
def loaded?() !version.nil? end
|
46
|
-
def load(file) Rdbms.load(name, file, user: user); @version = nil end
|
47
49
|
|
48
|
-
def
|
50
|
+
def load(file)
|
51
|
+
!loaded? or raise Internal, "Database #{name} is already loaded"
|
52
|
+
Rdbms.load(name, file, user: user)
|
53
|
+
version # Provoke load of version
|
54
|
+
end
|
49
55
|
|
50
|
-
def
|
56
|
+
def save(file)
|
57
|
+
loaded? or raise Internal, "Database #{name} is not loaded"
|
58
|
+
Rdbms.save(name, file)
|
59
|
+
@version = nil
|
60
|
+
end
|
51
61
|
|
52
|
-
#
|
62
|
+
def clean() recreate end # TODO: Find solution that doesn't involve dropping the database
|
53
63
|
|
54
|
-
|
55
|
-
@states = {
|
56
|
-
exist: [:create, :drop],
|
57
|
-
loaded: [:exist, :load, :recreate]
|
58
|
-
}
|
64
|
+
def to_s() name end
|
59
65
|
end
|
60
66
|
end
|