summaryrefslogtreecommitdiff
path: root/lib/sqitch.pod
blob: f81bc41db1ccc9c3e6a7d334a9c3a1381d130ea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
=encoding UTF-8

=head1 Name

sqitch - Sensible database change management

=head1 Synopsis

  sqitch <command> [options] [command-options] [args]

=head1 Description

Sqitch is a database change management application. It currently supports:

=over

=item * L<PostgreSQL|https://postgresql.org/> 8.4+

=item * L<YugabyteDB|https://www.yugabyte.com/yugabytedb/> 2.6+

=item * L<CockroachDB|https://www.cockroachlabs.com/product/> 21+

=item * L<SQLite|https://sqlite.org/> 3.8.6+

=item * L<MySQL|https://dev.mysql.com/> 5.1+

=item * L<MariaDB|https://mariadb.org> 10.0+

=item * L<Oracle|https://www.oracle.com/database/> 10g+,

=item * L<Firebird|https://www.firebirdsql.org/> 2.0+

=item * L<Vertica|https://www.vertica.com/> 7.2+

=item * L<Exasol|https://www.exasol.com/> 6.0+

=item * L<Snowflake|https://www.snowflake.net/>

=back

What makes it different from your typical
L<migration|Module::Build::DB>-L<style|DBIx::Migration> approaches? A few
things:

=over

=item No opinions

Sqitch is not tied to any framework, ORM, or platform. Rather, it is a
standalone change management system with no opinions about your database
engine, application framework, or development environment.

=item Native scripting

Changes are implemented as scripts native to your selected database engine.
Writing a L<PostgreSQL|https://postgresql.org/> application? Write SQL scripts
for L<C<psql>|https://www.postgresql.org/docs/current/static/app-psql.html>.
Writing an L<Oracle|https://www.oracle.com/us/products/database/>-backed app?
Write SQL scripts for L<SQL*Plus|https://www.orafaq.com/wiki/SQL*Plus>.

=begin comment

=item VCS integration

Sqitch likes to use your VCS history to determine in what order to execute
changes. No need to keep track of execution order; your VCS already tracks
information sufficient for Sqitch to figure it out for you.

=end comment

=item Dependency resolution

Database changes may declare dependencies on other changes -- even on changes
from other Sqitch projects. This ensures proper order of execution, even when
you've committed changes to your VCS out-of-order.

=item Deployment integrity

Sqitch manages changes and dependencies via a plan file, and employs a
L<Merkle tree|https://en.wikipedia.org/wiki/Merkle_tree> pattern similar to
L<Git|https://stackoverflow.com/a/18589734/> and
L<Blockchain|https://medium.com/byzantine-studio/blockchain-fundamentals-what-is-a-merkle-tree-d44c529391d7>
to ensure deployment integrity. As such, there is no need to number your
changes, although you can if you want. Sqitch doesn't much care how you name
your changes.


=item Iterative Development

Up until you L<tag|sqitch-tag> and L<release|sqitch-bundle> your project, you
can modify your change deployment scripts as often as you like. They're not
locked in just because they've been committed to your VCS. This allows you to
take an iterative approach to developing your database schema. Or, better, you
can do test-driven database development.

=begin comment

=item Bundling

Rely on your VCS history for deployment but have Sqitch bundle up changes for
distribution. Sqitch can read your VCS history and write out a plan file along
with the appropriate deployment and reversion scripts. Once the bundle is
installed on a new system, Sqitch can use the plan file to deploy or the
changes in the proper order.

=item Reduced Duplication

If you're using a VCS to track your changes, you don't have to duplicate
entire change scripts for simple changes. As long as the changes are
L<idempotent|https://en.wikipedia.org/wiki/Idempotence>, you can change
your code directly, and Sqitch will know it needs to be updated.

=end comment

=back

Ready to get started? Here's where:

=over

=item Sqitch Tutorials

Detailed tutorials demonstrating the creation, development, and maintenance
of a database with Sqitch.

=over

=item * L<PostgreSQL, YugabyteDB, CockroachDB Tutorial|sqitchtutorial>

=item * L<SQLite Tutorial|sqitchtutorial-sqlite>

=item * L<MySQL Tutorial|sqitchtutorial-mysql>

=item * L<Oracle Tutorial|sqitchtutorial-oracle>

=item * L<Firebird Tutorial|sqitchtutorial-firebird>

=item * L<Vertica Tutorial|sqitchtutorial-vertica>

=item * L<Exasol Tutorial|sqitchtutorial-exasol>

=item * L<Snowflake Tutorial|sqitchtutorial-snowflake>

=back

=item L<PDX.pm Presentation|https://speakerdeck.com/theory/sane-database-change-management-with-sqitch>

Slides from "Sane Database Management with Sqitch", presented to the Portland
Perl Mongers in January, 2013.

=item L<PDXPUG Presentation|https://vimeo.com/50104469>

Movie of "Sane Database Management with Sqitch", presented to the Portland
PostgreSQL Users Group in September, 2012.

=item L<Agile Database Development|https://speakerdeck.com/theory/agile-database-development-2ed>

Three-hour tutorial session on using L<Git|https://git-scm.org/>, test-driven
development with L<pgTAP|https://pgtap.org>, and change management with Sqitch.

=back

=begin comment

Eventually move to L<sqitchtutorial> or L<sqitchintro> or some such.

=end comment

=head2 Terminology

=over

=item C<change>

A named unit of change. A change name must be used in the file names of its
deploy and a revert scripts. It may also be used in a verify script file
name.

=item C<tag>

A known deployment state, pointing to a single change, typically corresponding
to a release. Think of it is a version number or VCS revision. A given point
in the plan may have any number of tags.

=item C<state>

The current state of the database. This is represented by the most
recently-deployed change. If the state of the database is the same as the most
recent change, then it is considered "up-to-date".

=item C<plan>

A list of one or more changes and their dependencies that define the order of
deployment execution. The plan is stored in a "plan file," usually named
F<sqitch.plan>. Sqitch reads the plan file to determine what changes to
execute to change the database from one state to another.

=item C<target>

A named database to which to deploy changes. Always has an associated
connection URI, and may also have an associated command-line client and
registry name.

=item C<registry>

The name of the database object where Sqitch's state and history data is
stored. Typically a schema name (as in PostgreSQL and Oracle) or a database
name (as in SQLite and MySQL).

=item C<add>

The act of adding a change to the plan. Sqitch will generate scripts for the
change, which you then may modify with the necessary code (typically DDLs) to
actually deploy, revert, and verify the change.

=item C<deploy>

The act of deploying changes to a database. Sqitch reads the plan, checks the
current state of the database, and applies all the changes necessary to either
bring the database up-to-date or to a requested state (a change name or tag).

=item C<revert>

The act of reverting database changes to reach an earlier deployment state.
Sqitch reads the list of deployed changes from the database and reverts
them in the reverse of the order in which they were applied. All changes
may be reverted, or changes may be reverted to a requested state (a change
name or tag).

=item C<committer>

User who commits or reverts changes to a database.

=item C<planner>

User who adds a change to the plan.

=back

=head1 Options

  -C --chdir --cd DIR       Change to directory before performing any actions.
     --etc-path             Print path to etc directory and exit.
     --no-pager             Do not pipe output into a pager.
     --quiet                Quiet mode with non-error output suppressed.
  -V --verbose              Increment verbosity.
     --version              Print version number and exit.
     --help                 Show a list of commands and exit.
     --man                  Print introductory documentation and exit.

=head1 Options Details

=over

=item C<--chdir>

=item C<--cd>

=item C<-C>

  sqitch --chdir dbproject
  sqitch --cd /usr/local/somedb
  sqitch -C dbcheckout

Change to the specified directory before performing any actions. Effectively the
same as:

  (cd somedir && sqitch ...)

But a bit friendlier when managing multiple projects.

=item C<--etc-path>

  sqitch --etc-path

Print out the path to the Sqitch F<etc> directory and exit. This is the
directory where the system-wide configuration file lives, as well as change
script templates.

=item C<--no-pager>

  sqitch --no-pager

Do not pipe Sqitch output into a pager. Currently limited to the C<log> and
C<plan> commands.

=item C<--quiet>

  sqitch --quiet

Suppress normal output messages. Error messages will still be emitted to
C<STDERR>. Overrides any value specified by C<--verbose>.

=item C<-V>

=item C<--verbose>

  sqitch --verbose
  sqitch -VVV

Pass multiple times to specify a value between 0 and 3 to determine how
verbose Sqitch should be. Unless C<--quiet> is specified, the default is 1,
meaning that Sqitch will output basic status messages as it does its thing.
Values of 2 and 3 each cause greater verbosity. Ignored if C<--quiet> is
specified.

=item C<--help>

  sqitch --help

Outputs a brief description all known Sqitch commands and exits.

=item C<--man>

  sqitch --man

Outputs this documentation and exits.

=item C<--version>

  sqitch --version

Outputs the program name and version and exits.

=back

=head1 Sqitch Commands

=over

=item L<C<init>|sqitch-init>

Create the plan file and directories for deploy, revert, and verify scripts if
they do not already exist. This command is useful for starting a new Sqitch
project.

=item L<C<status>|sqitch-status>

Output information about the current deployment state of a database, including
the name of the last deployed change, as well as any tags applied to it. If
any changes in the plan have not been deployed, they will be listed
separately.

=item L<C<log>|sqitch-log>

Search and Output the complete change history of a database. Provides
information about when changes were deployed, reverted, or failed, as well as
who planned and committed the changes, and when.

=item L<C<add>|sqitch-add>

Add a new change.

=item L<C<tag>|sqitch-tag>

List tags or tag the latest change.

=item L<C<rework>|sqitch-rework>

Rework an existing change.

=item L<C<target>|sqitch-target>

Manage target databases.

=item L<C<deploy>|sqitch-deploy>

Deploy changes to a database

=item L<C<revert>|sqitch-revert>

Revert changes from a database.

=item L<C<verify>|sqitch-verify>

Verify changes deployed to a database.

=item L<C<config>|sqitch-config>

Get and set project, user, or system Sqitch options.

=item L<C<bundle>|sqitch-bundle>

Bundle a Sqitch project for distribution. This command copies the Sqitch
configuration, plan, and deploy, revert, and verify scripts to a directory, so
that it can be packaged up for distribution, such as in an RPM or tarball.

=item L<C<help>|sqitch-help>

Show help for a specific command or, if no command is specified, show the same
documentation as C<--help>.

=back

=head1 Configuration

Sqitch configuration can be set up on a project, user, or system-wide basis.
The format of the configuration file, named F<sqitch.conf>, is the same as for
L<git>.

Here's an example of a configuration file that might be useful checked into a
VCS for a project that deploys to PostgreSQL and stores its deployment scripts
with the extension F<ddl> under the C<migrations> directory. It also wants
bundle to be created in the F<_build/sql> directory, and to deploy starting
with the "gamma" tag:

  [core]
      engine    = pg
      top_dir   = migrations
      extension = ddl

  [engine "pg"]
      target    = widgetopolis

  [revert]
      to        = gamma

  [bundle]
      from      = gamma
      tags_only = yes
      dest_dir  = _build/sql

  [target "widgetopolis"]
      uri       = db:pg:widgetopolis

And here's an example of useful configuration in F<~/.sqitch/sqitch.conf>, to
point to system-specific engine information:

  [user]
      name      = Marge N. O’Vera
      email     = marge@example.com

  [engine "pg"]
      client    = /usr/local/pgsql/bin/psql

  [engine "mysql"]
      client    = /usr/local/mysql/bin/mysql

  [engine "oracle"]
      client    = /usr/local/instantclient_11_2/sqlplus

  [engine "sqlite"]
      client    = /usr/local/bin/sqlite3

Various commands read from the configuration file and adjust their operation
accordingly. See L<sqitch-config> for a list.

=head1 See Also

The original design for Sqitch was sketched out in a number of blog posts:

=over

=item *

L<Simple SQL Change Management|https://justatheory.com/computers/databases/simple-sql-change-management.html>

=item *

L<VCS-Enabled SQL Change Management|https://justatheory.com/computers/databases/vcs-sql-change-management.html>

=item *

L<SQL Change Management Sans Duplication|https://justatheory.com/computers/databases/sql-change-management-sans-redundancy.html>

=back

Other tools that do database change management include:

=over

=item L<Rails migrations|https://guides.rubyonrails.org/migrations.html>

Numbered migrations for L<Ruby on Rails|https://rubyonrails.org/>.

=item L<Module::Build::DB>

Numbered changes in pure SQL, integrated with Perl's L<Module::Build> build
system. Does not support reversion.

=item L<DBIx::Migration>

Numbered migrations in pure SQL.

=item L<Versioning|https://www.depesz.com/2010/08/22/versioning/>

PostgreSQL-specific dependency-tracking solution by
L<depesz|https://www.depesz.com/>.

=back

=head1 Author

David E. Wheeler <david@justatheory.com>

=head1 License

Copyright (c) 2012-2023 iovation Inc., David E. Wheeler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

=cut