Skip to content

Commit f4f617c

Browse files
committed
WIP documentation
1 parent f69edb4 commit f4f617c

1 file changed

Lines changed: 94 additions & 18 deletions

File tree

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

Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ about_PSql_Deploy_Seeds
33

44
SHORT DESCRIPTION
55

6-
A seed is a SQL script that populates a target database with data.
6+
A PSql.Deploy seed is a T-SQL script that populates a target SQL Server or
7+
Azure SQL database with data. The Invoke-SqlSeed cmdlet applies one or more
8+
seeds to one or more target databases.
79

810

911
LONG DESCRIPTION
1012

11-
Source Directory Structure
13+
:: Source Directory Structure ::
1214

1315
PSql.Deploy expects seeds to have a specific filesystem layout.
1416

1517
src\ The source directory: a set of migrations and
16-
│ seeds for one database design. The name can vary.
18+
│ seeds for one database design. The path can vary.
1719
1820
├─ Seeds\ Seeds. Required only if there are any seeds.
1921
│ │
@@ -33,24 +35,98 @@ src\ The source directory: a set of migrations and
3335
└─ ... PSql.Deploy does not care about other files or
3436
directories present in the source directory.
3537

36-
Each subdirectory of {source-directory}\Seeds containing a _Main.sql file is a
37-
seed. The name of the subdirectory is the name of the seed. The _Main.sql
38-
file is the entry point for the seed.
38+
Given an arbitrary source directory, PSql.Deploy expects to find seeds in a
39+
Seeds subdirectory. Within the Seeds directory, each subdirectory containing a
40+
_Main.sql file is an individual seed. The name of the subdirectory determines
41+
the name of the seed. A seed name must be a valid directory name but is
42+
otherwise unrestricted.
3943

40-
Seeds support several magic comments for organizing code into modules with dependencies:
44+
The _Main.sql file is the entry point for the seed. The file is a T-SQL script
45+
with a few extensions to support modularity and parallelism.
4146

42-
--# MODULE: name [topic ...]
43-
Starts a new module with the specified name, optionally declaring provided
44-
topics.
4547

46-
--# PROVIDES: topic [topic ...]
47-
Indicates that the current module provides the specified topics.
48+
:: Seed Script SQLCMD Support ::
4849

49-
--# REQUIRES: topic [topic ...]
50-
Indicates that the current module requires the specified topics.
50+
PSql.Deploy seed scripts support a limited set of SQLCMD directives. Typical
51+
seeds use these directives to organize code into multiple files, to separate
52+
SQL batches, and to replace hard-coded values with variables.
5153

52-
--# WORKER: all|any
53-
Specifies worker execution mode. 'all' means the module executes on all
54-
workers; 'any' means it executes on any single worker.
54+
GO
55+
Ends the current SQL batch and begins a new one.
5556

56-
TODO: Describe seeds here.
57+
$(<name>)
58+
Replaced by the value of the SQLCMD variable <name>.
59+
60+
:r <file>
61+
Replaced by the contents of the specified file. The path is relative
62+
to the current PowerShell directory ($PWD or Get-Location), matching
63+
SQLCMD.EXE behavior.
64+
65+
To enable inclusion relative to the seed, PSql.Deploy predefines the
66+
SQLCMD variable 'Path' as the full path of the directory containing the
67+
_Main.sql file. Thus the directive
68+
69+
:r $(Path)\Foo.sql
70+
71+
includes the file Foo.sql from the same directory as _Main.sql.
72+
73+
The path may be enclosed within double quotes. This is mandatory if
74+
the path contains spaces, tabs, or double quotes. To include a double
75+
quote in the path, use two double quotes. Examples:
76+
77+
:r "$(Path)\My Script.sql"
78+
:r "$(Path)/My ""Special"" Script.sql"
79+
80+
Note that Windows does not support tabs or double quotes in file names.
81+
82+
:setvar <name> <value>
83+
Sets the SQLCMD variable <name> to the spacified <value>.
84+
85+
The value may be enclosed within double quotes. This is mandatory if
86+
the value contains spaces, tabs, or double quotes. To include a double
87+
quote in the value, use two double quotes.
88+
89+
:setvar MyVar MyValue
90+
:setvar MyVar "My Value"
91+
:setvar MyVar "My ""Special"" Value"
92+
93+
94+
:: Seed Script Parallelism Directives ::
95+
96+
Seeds typically consist of many statements that could execute in parallel if
97+
the language supported it. For example, inserting rows into different tables
98+
could occur in parallel, provided that all rows necessary to satisfy foreign
99+
key constraints are already present.
100+
101+
To enable parallelism, PSql.Deploy provides a set of directives to split a seed
102+
into 'modules' that can execute in parallel. Each module can declare its
103+
dependencies upon other modules. PSql.Deploy's Invoke-SqlSeed cmdlet then
104+
executes modules in parallel where possible but guarantees that each module's
105+
dependencies are satisfied before the module itself executes.
106+
107+
The dependency model is based on 'topics'. A topic is just an arbitrary name.
108+
Each module declares what topics it 'requires' and what topics it 'provides'.
109+
When a module requires a topic, PSql.Deploy will not execute that module until
110+
all modules providing that topic have completed.
111+
112+
Each module has a name, which also is a topic that the module provides. Seed
113+
code begins in the 'init' module.
114+
115+
PSql.Deploy seed directives take the form of magic comments. The following
116+
magic comments are available:
117+
118+
--# MODULE: <name> [<topic> ...]
119+
Starts a new module with the specified name, optionally declaring extra
120+
provided topics. The module name itself is a provided topic.
121+
122+
--# PROVIDES: <topic> [<topic> ...]
123+
Indicates that the current module provides the specified topics.
124+
125+
--# REQUIRES: <topic> [<topic> ...]
126+
Indicates that the current module requires the specified topics.
127+
128+
--# WORKER: all|any
129+
Specifies worker execution mode. 'all' means the module executes on all
130+
workers; 'any' means it executes on any single worker.
131+
132+
TODO: Describe all-worker modules.

0 commit comments

Comments
 (0)