psql-cm 0.0.7 → 0.0.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.
- data/History.md +8 -0
- data/README.md +46 -14
- data/lib/psql-cm/database.rb +1 -1
- data/lib/psql-cm/restore.rb +2 -2
- data/lib/psql-cm/submit.rb +5 -10
- data/lib/psql-cm/version.rb +1 -1
- metadata +3 -3
data/History.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
# PostgreSQL Change Management Tool
|
2
2
|
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
Experienced software engineers and database administrators know very well that
|
6
|
+
database systems need care and feeding, especially as they grow over time.
|
7
|
+
|
8
|
+
A Database Change Management System (DB CMS) is one method of carefully
|
9
|
+
accounting for changes to live database schemas in a controlled manner with
|
10
|
+
full history and auditability of who changed what and when.
|
11
|
+
|
12
|
+
A DB CMS itself is a well documented process and is typically required to meet
|
13
|
+
the following criteria,
|
14
|
+
|
15
|
+
- Managed the deployment of changes to a schema, specifically the DDL and DML,
|
16
|
+
in a controlled and auditable manner
|
17
|
+
|
18
|
+
- Control the deployment / migration of DDL from one Server/Database/Schema to
|
19
|
+
another
|
20
|
+
|
21
|
+
- Integrate directly with the database system, backups and restores while
|
22
|
+
preserving the integrity of the data schema within the CMS
|
23
|
+
|
24
|
+
- Regenerate DDL for Disaster Recovery in the absence of database backups
|
25
|
+
|
26
|
+
psql-cm is a tool which was created to help make achieving these goals easier.
|
27
|
+
|
3
28
|
## What psql-cm is
|
4
29
|
|
5
30
|
This project is a tool to assist with an ITIL like change management process
|
@@ -51,14 +76,14 @@ to separate multiple database names.
|
|
51
76
|
Dump the current database schema to the specified --sql-path directory, if none
|
52
77
|
specified it dumps to $PWD/sql
|
53
78
|
|
54
|
-
$ psql-cm dump --database psqlcm_test
|
79
|
+
$ psql-cm dump --database psqlcm_test --sql-path $HOME/sql
|
55
80
|
|
56
81
|
## Restore
|
57
82
|
|
58
83
|
Restore a previously psql-cm dumped database schema into a brand new postgresql
|
59
84
|
database cluster.
|
60
85
|
|
61
|
-
$ psql-cm restore --database psqlcm_test
|
86
|
+
$ psql-cm restore --database psqlcm_test --sql-path $HOME/sql
|
62
87
|
|
63
88
|
## Submit
|
64
89
|
|
@@ -155,8 +180,8 @@ a find command on \*nix:
|
|
155
180
|
sql/psqlcm_test/schema_one.sql
|
156
181
|
sql/psqlcm_test/schema_two.sql
|
157
182
|
|
158
|
-
We can now do a restore
|
159
|
-
|
183
|
+
We can now do a restore by droping the database and then running the psql-cm
|
184
|
+
restore action.
|
160
185
|
|
161
186
|
$ dropdb psqlcm_test
|
162
187
|
$ psql-cm --database psqlcm_test restore
|
@@ -183,17 +208,24 @@ To play around inside of a running psql-cm Ruby environment use the console:
|
|
183
208
|
The 'Walkthrough' from above is encoded as rake tasks, each step can be
|
184
209
|
seen including all debugging output by running:
|
185
210
|
|
186
|
-
rake
|
187
|
-
rake
|
188
|
-
rake
|
189
|
-
rake
|
190
|
-
rake
|
191
|
-
rake
|
192
|
-
rake
|
193
|
-
rake
|
194
|
-
rake
|
211
|
+
rake build # Build the psql-cm gem
|
212
|
+
rake clean # Remove sql/ in the current working directory
|
213
|
+
rake console # Console, builds installs then runs console
|
214
|
+
rake create # Create database psqlcm_development, and two schemas
|
215
|
+
rake debug # Enable debugging using environment variable DEBUG
|
216
|
+
rake drop # Drop the database psqlcm_development
|
217
|
+
rake dump # Run psql-cm dump on psqlcm_development
|
218
|
+
rake install # Build then install the psql-cm gem
|
219
|
+
rake restore # Run psql-cm restore on psqlcm_development
|
220
|
+
rake setup # Run psql-cm setup on schemas within psqlcm_development
|
221
|
+
rake submit:file # Run psql-cm submit with a file based change
|
222
|
+
rake submit:string # Run psql-cm submit with a string change from cli
|
195
223
|
|
196
224
|
Specifically to do a full-cycle walkthrough on the psqlcm\_development database,
|
197
225
|
|
198
|
-
rake
|
226
|
+
rake create setup dump drop restore submit:string submit:file
|
227
|
+
|
228
|
+
Then to re-run the full cycle we need to add 'drop' in the front,
|
229
|
+
|
230
|
+
rake drop create setup dump drop restore submit:string submit:file
|
199
231
|
|
data/lib/psql-cm/database.rb
CHANGED
data/lib/psql-cm/restore.rb
CHANGED
@@ -23,10 +23,10 @@ module PSQLCM
|
|
23
23
|
sh "psql #{db(database).psql_args} #{database} < #{cm_file}"
|
24
24
|
|
25
25
|
ensure_cm_table_exists(database,schema)
|
26
|
-
|
26
|
+
Tempfile.open('base.sql') do |temp_file|
|
27
|
+
row = db(database).exec("SELECT content from #{schema}.#{config.cm_table}
|
27
28
|
WHERE is_base IS true ORDER BY created_at
|
28
29
|
DESC LIMIT 1;")
|
29
|
-
Tempfile.open('base.sql') do |temp_file|
|
30
30
|
temp_file.write(row)
|
31
31
|
sh "psql #{db(database).psql_args} #{database} < #{temp_file.path}"
|
32
32
|
end
|
data/lib/psql-cm/submit.rb
CHANGED
@@ -4,7 +4,7 @@ module PSQLCM
|
|
4
4
|
databases.each do |database|
|
5
5
|
schemas(database).each do |schema|
|
6
6
|
if config.change.to_s.empty?
|
7
|
-
halt! "Content must be given! (--
|
7
|
+
halt! "Content must be given! (--change=<file or \"sql string\">)"
|
8
8
|
elsif File.exists?(config.change)
|
9
9
|
content = File.open(config.change, 'r') { |file| file.read }
|
10
10
|
else # SQL String
|
@@ -25,18 +25,13 @@ module PSQLCM
|
|
25
25
|
debug "submit> #{database}.#{schema}.#{config.cm_table}: #{config.change}"
|
26
26
|
db(database).exec(
|
27
27
|
"INSERT INTO #{schema}.#{config.cm_table}
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
(is_base,implementer,content)
|
29
|
+
VALUES (false,$1,$2)",
|
30
|
+
[implementer,content]
|
31
|
+
)
|
32
32
|
end # schemas
|
33
33
|
end # databases
|
34
34
|
end # def submit!
|
35
35
|
|
36
|
-
private
|
37
|
-
|
38
|
-
def validate(change)
|
39
|
-
|
40
|
-
end
|
41
36
|
end
|
42
37
|
end
|
data/lib/psql-cm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psql-cm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: 1.3.6
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.23
|
72
72
|
signing_key:
|
73
73
|
specification_version: 3
|
74
74
|
summary: PostgreSQL CM
|