Skip to content

Commit 059c077

Browse files
committed
WIP: Documentation
1 parent fb53086 commit 059c077

2 files changed

Lines changed: 121 additions & 13 deletions

File tree

PSql.Deploy.Engine/Migrations/MigrationPlanner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Migration Ordering
5454
3 │ Pre │ Core ^^^^ │ Post │
5555
4 │ │ Pre Core │ Post │
5656
5 │ │ ^^^ Pre Core │ Post │
57-
Time──> ^^^
57+
Time──> ^^^
5858
5959
Rules
6060
=====
@@ -68,7 +68,7 @@ Migration N's Cores are guaranteed to run after all of Migration N-1's Cores.
6868
Migration N's Posts are guaranteed to run after all of Migration N-1's Posts.
6969
7070
Only the greatest dependency name for each migration matters.
71-
If Migration A depends on Migration B, then B's Post will run before A's Pre.
71+
If Migration B depends on Migration A, then A's Post will run before B's Pre.
7272
*/
7373

7474
private readonly MigrationPlan _plan;

PSql.Deploy/en-US/about_PSql_Deploy.help.txt

Lines changed: 119 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ src\ The source directory: a set of migrations and
5151

5252
See the sections below for more details about migrations and seeds.
5353

54+
TODO: SQLCMD mode support.
55+
GO
56+
Breaks the script into batches.
57+
58+
$(name)
59+
Replaced by the value of the variable 'name' in the migration or seed.
60+
61+
:r <file>
62+
Include the contents of the specified file in the migration. The variable
63+
$(Path) is available in the included file and expands to the path of the
64+
migration or seed file that includes the file.
65+
66+
:setvar <name> <value>
67+
Set a variable for the duration of the migration or seed. The variable
68+
$(name) is available in the included file and expands to the value set by
69+
this directive.
70+
71+
TODO: General magic comments description.
72+
5473

5574
Target Parameter
5675
----------------
@@ -117,30 +136,115 @@ To facilitate zero- and low-downtime deployments, PSql.Deploy splits deployment
117136
into three logical phases: Pre, Core, and Post. Each phase represents a
118137
different moment within a deployment process. Each SQL statement within a
119138
migration executes in exactly one of these phases. One migration can contain
120-
statements for multiple phases.
121-
122-
The three phases are:
139+
statements for multiple phases. The purposes of the phases are as follows:
123140

124-
- Pre
141+
Pre
125142
This phase occurs before deployment of the workloads that use the target
126143
database, perhaps while previously deployed workloads are still running.
127144
Migration statements in this phase should make the database compatible with
128-
the upcoming workload deployment retaining compatibility with the existing
129-
workloads.
145+
the upcoming workload deployment but should retain compatibility with any
146+
existing workloads.
130147

131-
- Core
148+
Core
132149
This phase occurs at some arbitrary point between the Pre and Post phases.
133150
PSql.Deploy interprets statements within this phase as requiring downtime,
134-
explicitly breaking a zero-downtime deployment schenario.
151+
explicitly breaking a zero-downtime deployment schenario. Migration
152+
statements in this phase should make the database compatible with newly
153+
deployed workloads and need not retain compatibility with any previously
154+
deployed workloads. This phase is also suitable for deployment scenarios
155+
where downtime is not a concern.
135156

136-
- Post
157+
Post
137158
This phase occurs after deployment of the workloads that use the target
138159
database, while those workloads are running. Migration statements in this
139160
phase should finalize or clean up after the changes made in earlier phases
140161
while retaining compatibility with the deployed workloads.
141162

142-
Deployments for which downtime is not a concern can use any phase, with Core
143-
being the easiest to use.
163+
Dependencies
164+
165+
PSql.Deploy enables one migration to declare a dependency on another migration.
166+
The Invoke-SqlMigrations cmdlet handles a dependency in one of two ways. If
167+
the required migration has been applied fully to a target database, then the
168+
dependency is satisfied already, and the cmdlet applies the depending migration
169+
normally to that target database. If neither the required migration nor the
170+
requiring migration has been applied yet to a target database, then the cmdlet
171+
moves Pre and Post statements into the Core phase as required to satisfy the
172+
dependency and preserve the guarantees that the cmdlet makes about the order of
173+
migration statements. Note that this makes dependency resolution incompatible
174+
with zero-downtime deployment scenarios, because Core entails downtime.
175+
176+
Ordering Guarantees
177+
178+
The Invoke-SqlMigrations cmdlet makes the following guarantees about the order
179+
of migration statement execution:
180+
181+
- A migration's Pre-phase statements are guaranteed to execute after all
182+
previous migrations' Pre-phase statements.
183+
184+
- A migration's Core-phase statements are guaranteed to execute after all
185+
previous migrations' Core-phase statements.
186+
187+
- A migration's Post-phase statements are guaranteed to execute after all
188+
previous migrations' Post-phase statements.
189+
190+
- If migration B depends on migration A, then A's Post-phase statements are
191+
guaranteed to execute before B's Pre-phase statements.
192+
193+
Example 1: No dependencies
194+
195+
These migrations:
196+
1 │ Pre Core Post
197+
2 │ Pre Core Post
198+
3 │ Pre Core Post
199+
4 │ Pre Core Post
200+
5 │ Pre Core Post
201+
202+
Yield this order operations:
203+
│ Pre │ Core │ Post │
204+
══╪════════════════════╪══════════════════════════╪══════════════════════════╡
205+
1 │ Pre │ Core │ Post │
206+
2 │ Pre │ Core │ Post │
207+
3 │ Pre │ Core │ Post │
208+
4 │ Pre │ Core │ Post │
209+
5 │ Pre │ Core │ Post │
210+
Time──>
211+
212+
Example 2: One dependency
213+
214+
These migrations:
215+
1 │ Pre Core Post
216+
2 │ Pre Core Post <──╮
217+
3 │ Pre Core Post │
218+
4 │ Pre Core Post ───╯ Migration 4 depends on Migration 2
219+
5 │ Pre Core Post
220+
221+
Yield this order operations:
222+
│ Pre │ Core │ Post │
223+
══╪═════════════╪════════════════════════════════════════════╪════════════════╡
224+
1 │ Pre │ Core Post │ │
225+
2 │ Pre │ Core ^^^^ Post │ │
226+
3 │ Pre │ Core ^^^^ │ Post │
227+
4 │ │ Pre Core │ Post │
228+
5 │ │ ^^^ Pre Core │ Post │
229+
Time──> ^^^
230+
231+
Magic Comments
232+
233+
A migration may contain 'magic comments', which are special comments that the
234+
Invoke-SqlMigrations cmdlet interprets as directives. The cmdlet supports the
235+
following magic comments:
236+
237+
--# PRE
238+
Causes subsequent SQL text to execute in the Pre phase.
239+
240+
--# CORE
241+
Causes subsequent SQL text to execute in the Core phase.
242+
243+
--# POST
244+
Causes subsequent SQL text to execute in the Post phase.
245+
246+
--# REQUIRES: <migration-name> ...
247+
Declares a dependency on one or more migrations.
144248

145249
Example Migration Naming Schemes
146250

@@ -172,6 +276,10 @@ Here are some example migration naming schemes:
172276
Best for: teams with multiple migration authors where it is useful to
173277
associate migrations with work items, pull requests, etc.
174278

279+
Squashes
280+
281+
TODO: Describe squashes here.
282+
175283

176284
Seeds
177285
-----

0 commit comments

Comments
 (0)