prick 0.19.0 → 0.20.1

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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -4
  3. data/README.md +7 -7
  4. data/Rakefile +3 -1
  5. data/TODO +13 -11
  6. data/bin/console +2 -1
  7. data/doc/build-yml.txt +14 -0
  8. data/exe/prick +237 -19
  9. data/lib/builder/batch.rb +147 -0
  10. data/lib/builder/builder.rb +122 -0
  11. data/lib/builder/node.rb +189 -0
  12. data/lib/builder/node_pool.rb +105 -0
  13. data/lib/builder/parser.rb +120 -0
  14. data/lib/local/command.rb +193 -0
  15. data/lib/{prick → local}/git.rb +148 -22
  16. data/lib/local/timer.rb +98 -0
  17. data/lib/prick/constants.rb +54 -66
  18. data/lib/prick/diff.rb +28 -18
  19. data/lib/prick/prick_version.rb +161 -0
  20. data/lib/prick/state.rb +80 -165
  21. data/lib/prick/version.rb +2 -163
  22. data/lib/prick.rb +38 -24
  23. data/lib/share/init/.gitignore +10 -0
  24. data/lib/share/init/.prick-context +2 -0
  25. data/lib/share/init/.rspec +3 -0
  26. data/{share/schema/schema/public → lib/share/init/migration}/.keep +0 -0
  27. data/lib/share/init/prick.yml +6 -0
  28. data/lib/share/init/schema/.keep +0 -0
  29. data/lib/share/init/schema/build.yml +2 -0
  30. data/lib/share/init/schema/prick/.keep +0 -0
  31. data/lib/share/init/schema/prick/build.yml +5 -0
  32. data/lib/share/init/schema/prick/data.sql +6 -0
  33. data/{share/schema → lib/share/init}/schema/prick/tables.sql +2 -3
  34. data/lib/share/init/schema/public/.keep +0 -0
  35. data/lib/share/init/spec/prick_helper.rb +1 -0
  36. data/lib/share/init/spec/prick_spec.rb +6 -0
  37. data/lib/share/init/spec/spec_helper.rb +50 -0
  38. data/lib/share/migrate/migration/build.yml +4 -0
  39. data/lib/share/migrate/migration/diff.after-tables.sql +0 -0
  40. data/lib/share/migrate/migration/diff.before-tables.sql +0 -0
  41. data/lib/share/migrate/migration/diff.tables.sql +0 -0
  42. data/lib/subcommand/prick-build.rb +55 -0
  43. data/lib/subcommand/prick-create.rb +78 -0
  44. data/lib/subcommand/prick-drop.rb +25 -0
  45. data/lib/subcommand/prick-fox.rb +62 -0
  46. data/lib/subcommand/prick-init.rb +46 -0
  47. data/lib/subcommand/prick-make.rb +202 -0
  48. data/lib/subcommand/prick-migrate.rb +37 -0
  49. data/lib/subcommand/prick-release.rb +23 -0
  50. data/lib/subcommand/prick-setup.rb +20 -0
  51. data/lib/subcommand/prick-teardown.rb +18 -0
  52. data/prick.gemspec +32 -21
  53. metadata +95 -76
  54. data/.gitignore +0 -29
  55. data/.travis.yml +0 -7
  56. data/doc/create_release.txt +0 -17
  57. data/doc/flow.txt +0 -98
  58. data/doc/migra +0 -1
  59. data/doc/migrations.txt +0 -172
  60. data/doc/notes.txt +0 -116
  61. data/doc/prick.txt +0 -114
  62. data/doc/sh.prick +0 -316
  63. data/lib/ext/algorithm.rb +0 -14
  64. data/lib/ext/fileutils.rb +0 -26
  65. data/lib/ext/forward_method.rb +0 -18
  66. data/lib/ext/pg.rb +0 -18
  67. data/lib/ext/shortest_path.rb +0 -44
  68. data/lib/prick/archive.rb +0 -124
  69. data/lib/prick/branch.rb +0 -265
  70. data/lib/prick/builder.rb +0 -246
  71. data/lib/prick/cache.rb +0 -34
  72. data/lib/prick/command.rb +0 -104
  73. data/lib/prick/database.rb +0 -82
  74. data/lib/prick/dsort.rb +0 -151
  75. data/lib/prick/ensure.rb +0 -119
  76. data/lib/prick/exceptions.rb +0 -25
  77. data/lib/prick/head.rb +0 -189
  78. data/lib/prick/migration.rb +0 -70
  79. data/lib/prick/program.rb +0 -287
  80. data/lib/prick/project.rb +0 -626
  81. data/lib/prick/rdbms.rb +0 -137
  82. data/lib/prick/schema.rb +0 -27
  83. data/lib/prick/share.rb +0 -64
  84. data/libexec/strip-comments +0 -33
  85. data/make_releases +0 -72
  86. data/make_schema +0 -10
  87. data/share/diff/diff.after-tables.sql +0 -4
  88. data/share/diff/diff.before-tables.sql +0 -4
  89. data/share/diff/diff.tables.sql +0 -8
  90. data/share/features/diff.sql +0 -2
  91. data/share/features/feature/diff.sql +0 -2
  92. data/share/features/feature/migrate.sql +0 -2
  93. data/share/features/features.sql +0 -2
  94. data/share/features/features.yml +0 -2
  95. data/share/features/migrations.sql +0 -4
  96. data/share/gitignore +0 -2
  97. data/share/migration/diff.tables.sql +0 -8
  98. data/share/migration/features.yml +0 -6
  99. data/share/migration/migrate.sql +0 -3
  100. data/share/migration/migrate.yml +0 -8
  101. data/share/migration/tables.sql +0 -3
  102. data/share/schema/build.yml +0 -14
  103. data/share/schema/schema/build.yml +0 -3
  104. data/share/schema/schema/prick/build.yml +0 -14
  105. data/share/schema/schema/prick/data.sql +0 -7
  106. data/share/schema/schema/prick/schema.sql +0 -3
  107. data/share/schema/schema/public/build.yml +0 -13
  108. data/share/schema/schema.sql +0 -3
  109. data/test_assorted +0 -192
  110. data/test_feature +0 -112
  111. data/test_refactor +0 -34
  112. data/test_single_dev +0 -83
data/lib/prick/program.rb DELETED
@@ -1,287 +0,0 @@
1
-
2
- require "pg_conn"
3
- require "prick.rb"
4
-
5
- module Prick
6
- # Implements the command line commands
7
- class Program
8
- # Lazy-constructed because Project can only be initialized when the
9
- # directory structure is present
10
- def project() @project ||= Project.load end
11
-
12
- attr_accessor :quiet
13
- attr_accessor :verbose
14
- attr_accessor :current_directory # Path to the directory where prick was called from
15
-
16
- def initialize(current_directory = Dir.getwd, quiet: false, verbose: false)
17
- @current_directory = current_directory
18
- @quiet = quiet
19
- @verbose = verbose
20
- end
21
-
22
- # Check if the git repository is clean. Raise an error if not
23
- def check_clean()
24
- Git.clean? or raise Error, "Repository is dirty - please commit your changes first"
25
- end
26
-
27
- # Create project directory structure
28
- def init(name, user, directory)
29
- !Project.exist?(directory) or raise Error, "Directory #{directory} is already initialized"
30
- Project.create(name, user, directory)
31
- if name != directory
32
- mesg "Initialized project #{name} in #{directory}"
33
- else
34
- mesg "Initialized project #{name}"
35
- end
36
- end
37
-
38
- def info
39
- if project.tag?
40
- puts "At v#{project.version} tag"
41
- else
42
- puts "On branch #{project.head.name}, #{project.version}"
43
- end
44
- puts " Git is " + (Git.clean? ? "clean" : "dirty")
45
- bv = project.head.version
46
- dv = project.database.version
47
- sv = project.head.schema.version
48
- puts " Database version: #{dv}" + (dv != bv ? " (mismatch)" : "")
49
- puts " Schema version : #{sv}" + (sv != bv ? " (mismatch)" : "")
50
- end
51
-
52
- def list_releases(migrations: false, cancelled: false)
53
- raise NotYet
54
- end
55
-
56
- def list_migrations
57
- raise NotYet
58
- end
59
-
60
- def list_upgrades(from = nil, to = nil)
61
- raise NotYet
62
- end
63
-
64
- def list_cache
65
- project.cache.list.each { |l| puts l }
66
- end
67
-
68
- def build(database, version, state_file, nocache)
69
- into_mesg = database && "into #{database}"
70
- version_mesg = version ? "v#{version}" : "current schema"
71
- version &&= Version.new(version)
72
- version.nil? || Git.tag?(version) or raise Error, "Can't find tag v#{version}"
73
- database = database ? Database.new(database, project.user) : project.database(version)
74
- drop_users(database.name)
75
- Builder.state_file = state_file
76
- project.build(database, version: version)
77
- project.save(database) if version && !nocache
78
- mesg "Built", version_mesg, into_mesg
79
- end
80
-
81
- def make(database, version, nocache)
82
- version &&= Version.new(version)
83
- version.nil? || Git.tag?(version) or raise Error, "Can't find tag v#{version}"
84
- if !nocache && version && project.cache.exist?(version)
85
- load(database, version)
86
- else
87
- build(database, version, nocache)
88
- end
89
- end
90
-
91
- def make_clean(all)
92
- project.cache.clean.each { |file| mesg "Removed cache file #{File.basename(file)}" }
93
- drop(nil, all)
94
- end
95
-
96
- def load(database, file_or_version)
97
- check_owned(database) if database
98
- into_mesg = database && "into #{database}"
99
- if version = Version.try(file_or_version)
100
- database = database ? Database.new(database, project.user) : project.database(version)
101
- project.load(database, version: version)
102
- mesg "Loaded v#{version}", into_mesg, "from cache"
103
- else
104
- file = file_or_version
105
- project.load(database, file: norm_path(file))
106
- mesg "Loaded #{File.basename(file)}", into_mesg
107
- end
108
- end
109
-
110
- def save(version, file)
111
- database = project.database(version)
112
- database.exist? or raise "Can't find database '#{database}'"
113
- project.save(database, file: norm_path(file))
114
- mesg "Saved #{database} to #{file || 'cache'}"
115
- end
116
-
117
- def drop(database, all)
118
- database.nil? || !all or raise Error, "Can't use --all when database is given"
119
- return if !Rdbms.exist_database?(database)
120
- if database
121
- check_owned(database)
122
- dbs = [database]
123
- else
124
- dbs = Rdbms.list_databases(Prick.database_re(project.name))
125
- dbs << project.name if all && project.database.exist?
126
- end
127
- dbs += Rdbms.list_databases(Prick.tmp_databases_re(project.name)) # FIXME: Only used in dev
128
- dbs.each { |db|
129
- Rdbms.drop_database(db)
130
- drop_users db
131
- mesg "Dropped database #{db}"
132
- }
133
- end
134
-
135
- # Drop all users that follows the per-database-user naming convention
136
- # ("<database>__<username>")
137
- def drop_users(database)
138
- PgConn.new("postgres") { |postgres|
139
- users = postgres.role.list.grep(/^#{database.sub(/-/, "_")}__/)
140
- if postgres.rdbms.exist?(database)
141
- PgConn.new(database) { |conn| conn.role.drop users, cascade: true }
142
- else
143
- postgres.role.drop users
144
- end
145
- }
146
- end
147
-
148
- # `select` is a tri-state variable that can be :tables, :no_tables, or :all
149
- # (or any other value)
150
- def diff(from, to, mark, select)
151
- diff = project.diff(from && Version.new(from), to && Version.new(to))
152
- if !diff.same?
153
- if select != :tables && !diff.before_table_changes.empty?
154
- puts "-- BEFORE TABLE CHANGES" if mark
155
- puts diff.before_table_changes
156
- end
157
- if select != :no_tables && !diff.table_changes.empty?
158
- puts "-- TABLE CHANGES" if mark
159
- puts diff.table_changes
160
- end
161
- if select != :tables && !diff.after_table_changes.empty?
162
- puts "-- AFTER TABLE CHANGES" if mark
163
- puts diff.after_table_changes
164
- end
165
- end
166
- end
167
-
168
- def migrate
169
- raise NotYet
170
- end
171
-
172
- def prepare_release(fork)
173
- project.prepare_release(fork)
174
- end
175
-
176
- def prepare_feature(name)
177
- raise NotYet
178
- end
179
-
180
- def prepare_migration(from = nil)
181
- raise NotYet
182
- end
183
-
184
- def prepare_schema(name)
185
- project.prepare_schema(name)
186
- end
187
-
188
- def prepare_diff(version = nil)
189
- # Helpful check to ensure the user has built the current version
190
- # Diff.same?(to_db, database) or
191
- # raise Error, "Schema and project database are not synchronized"
192
-
193
- project.prepare_diff(version || project.version)
194
- if FileUtils.compare_file(TABLES_DIFF_PATH, TABLES_DIFF_SHARE_PATH)
195
- mesg "Created diff. No table changes found, no manual migration updates needed"
196
- else
197
- mesg "Created diff. Please inspect #{TABLES_DIFF_PATH} and incorporate the"
198
- mesg "changes in #{MIGRATION_DIR}/migrate.sql"
199
- end
200
- end
201
-
202
- def include(name)
203
- raise NotYet
204
- end
205
-
206
- def check
207
- version ||=
208
- if project.prerelease? || project.migration?
209
- project.branch.base_version
210
- else
211
- project.branch.version
212
- end
213
- project.check_migration(version)
214
- end
215
-
216
- def create_release(version = nil)
217
- if project.prerelease_branch?
218
- raise NotYet
219
- elsif project.release_branch?
220
- project.create_release(Version.new(version))
221
- else
222
- raise Error, "You need to be on a release or pre-release branch to create a new release"
223
- end
224
- mesg "Created release v#{project.head.version}"
225
- end
226
-
227
- def create_prerelease(version = nil)
228
- raise NotYet
229
- end
230
-
231
- def create_feature(name)
232
- raise NotYet
233
- end
234
-
235
- def cancel(version)
236
- raise NotYet
237
- end
238
-
239
- def generate_schema
240
- project.generate_schema
241
- end
242
-
243
- def generate_migration
244
- project.generate_migration
245
- end
246
-
247
- def upgrade
248
- raise NotYet
249
- end
250
-
251
- # TODO: Create a Backup class and a Project#backup_store object
252
- def backup(file = nil)
253
- path = norm_path(file) ||
254
- File.join(SPOOL_DIR, "#{project.name}-#{Time.now.utc.strftime("%Y%m%d-%H%M%S")}.sql.gz")
255
- project.save(file: path)
256
- mesg "Backed-up database to #{file}"
257
- end
258
-
259
- def restore(file = nil)
260
- path = norm_path(file) || Dir.glob(File.join(SPOOL_DIR, "#{name}-*.sql.gz")).sort.last
261
- File.exist?(path) or raise Error, "Can't find #{file || "any backup file"}"
262
- project.load(file: path)
263
- mesg "Restored database from #{file}"
264
- end
265
-
266
- protected
267
- def check_owned(database)
268
- database =~ ALL_DATABASES_RE or raise Error, "Not a prick database: #{database}"
269
- project_name = $1
270
- project_name == project.name or raise Error, "Database not owned by this prick project: #{database}"
271
- end
272
-
273
- # Expand relative path with respect to the directory where prick was called
274
- # from. Return nil if file is nil
275
- def norm_path(file)
276
- if file && !file.start_with?("/")
277
- File.join(current_directory, file)
278
- else
279
- file
280
- end
281
- end
282
-
283
- def mesg(*args) puts args.compact.grep(/\S/).join(' ') if !quiet end
284
- def verb(*args) puts args.compact.grep(/\S/).join(' ') if verbose end
285
- end
286
- end
287
-