Skip to content

Commit

Permalink
Merge pull request #1 from datalust/dev
Browse files Browse the repository at this point in the history
First release from master
  • Loading branch information
nblumhardt authored Jul 21, 2017
2 parents e787867 + faca020 commit 5510502
Show file tree
Hide file tree
Showing 213 changed files with 49,536 additions and 145 deletions.
1 change: 1 addition & 0 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function Update-WixVersion($version)
function Execute-MSBuild
{
& msbuild ./piggy.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64
if($LASTEXITCODE -ne 0) { exit 2 }
}

function Execute-Tests
Expand Down
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,80 @@

A friendly PostgreSQL script runner in the spirit of [DbUp](https://github.com/DbUp/DbUp).

[![Build status](https://ci.appveyor.com/api/projects/status/889gkdpvjbjuhkfg?svg=true)](https://ci.appveyor.com/project/datalust/piggy)

### What is Piggy?

Piggy is a simple command-line tool for managing schema and data changes to PostgreSQL databases. Piggy looks for `.sql` files in a directory and applies them to the database in order, using transactions and a change log table to ensure each script runs only once per database.

### Installation

Piggy is available as a Windows MSI installer from [the releases page](https://github.com/datalust/piggy/releases). Linux and macOS are supported, but currently require the `Datalust.Piggy` project in this repository to be built from source.

### Organizing change scripts

Your `.sql` files should be named so that they will sort lexicographically in the order they need to be executed:

```
001-create-schema.sql
002-create-users-table.sql
003-...
```

If the scripts are arranged in subfolders, these can be ordered as well:

```
v1/
001-create-schema.sql
002-create-users-table.sql
003-...
v2/
001-rename-users-table.sql
```

Each script is just regular SQL with any DDL or DML statements required to make a change to the database.

### Applying scripts

Scripts must be applied starting from a _script root_. Piggy searches for `.sql` files and generates script names like `/v1/001-create-schema.sql` using each script's filename relative to the script root. These relative filenames are checked against the change log table to determine which of them need to be run.

The script root is specified with `-s`. Other parameters identify the database server host, the database name, username and password:

```
piggy apply -s <scripts> -h <host> -d <database> -u <username> -p <password>
```

If the database does not exist, Piggy will create it using sensible defaults. To opt out of this behavior, add the `--no-create` flag.

For more detailed usage information, run `piggy help apply`; to see all available commands run `piggy help`.

### Transactions

Piggy wraps each script in a transaction that also covers the change log table update. A few DDL statements can't run within a transaction in PostgreSQL - in these cases, add:

```sql
-- PIGGY NO TRANSACTION
```

as the first line of the script.

### Variable substitution

Piggy uses `$var$` syntax for replaced variables:

```sql
create table $schema$.users;
insert into users (name) values ('$admin$');
```

Values are inserted using pure text substitution: no escaping or other processing is applied. If no value is supplied for a variable that appears in a script, Piggy will leave the script unchanged (undefined variables will not be replaced with the empty string).

Variables are supplied on the command-line with the `-v` flag:

```
piggy apply ... -v schema=myapp -v admin=myuser
```

### Change log

The change log is stored in the target database in `piggy.changes`. The `piggy log` command can be used to view applied change scripts.
28 changes: 28 additions & 0 deletions build/wix/LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright (c) .NET Foundation and contributors.
This software is released under the Microsoft Reciprocal License (MS-RL) (the "License"); you may not use the software except in compliance with the License.

The text of the Microsoft Reciprocal License (MS-RL) can be found online at:
http://opensource.org/licenses/ms-rl


Microsoft Reciprocal License (MS-RL)

This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.

1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.

2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.

3. Conditions and Limitations
(A) Reciprocal Grants- For any file you distribute that contains code from the software (in source code or binary format), you must provide recipients the source code to that file along with a copy of this license, which license will govern that file. You may license other files that are entirely your own work and do not contain code from the software under any terms you choose.
(B) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(C) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(D) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(E) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(F) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
Binary file added build/wix/LuxTasks.dll
Binary file not shown.
Binary file added build/wix/ThmViewer.exe
Binary file not shown.
Binary file added build/wix/WixBalExtension.dll
Binary file not shown.
Binary file added build/wix/WixComPlusExtension.dll
Binary file not shown.
Binary file added build/wix/WixCop.exe
Binary file not shown.
Binary file added build/wix/WixDependencyExtension.dll
Binary file not shown.
Binary file added build/wix/WixDifxAppExtension.dll
Binary file not shown.
Binary file added build/wix/WixDirectXExtension.dll
Binary file not shown.
Binary file added build/wix/WixFirewallExtension.dll
Binary file not shown.
Binary file added build/wix/WixGamingExtension.dll
Binary file not shown.
Binary file added build/wix/WixHttpExtension.dll
Binary file not shown.
Binary file added build/wix/WixIIsExtension.dll
Binary file not shown.
Binary file added build/wix/WixLuxExtension.dll
Binary file not shown.
Binary file added build/wix/WixMsmqExtension.dll
Binary file not shown.
Binary file added build/wix/WixNetFxExtension.dll
Binary file not shown.
Binary file added build/wix/WixPSExtension.dll
Binary file not shown.
Binary file added build/wix/WixSqlExtension.dll
Binary file not shown.
Binary file added build/wix/WixTagExtension.dll
Binary file not shown.
Binary file added build/wix/WixTasks.dll
Binary file not shown.
Binary file added build/wix/WixToolset.BlockDeflateStream.dll
Binary file not shown.
Binary file added build/wix/WixToolset.Data.dll
Binary file not shown.
Binary file added build/wix/WixToolset.Dtf.Compression.Cab.dll
Binary file not shown.
Binary file added build/wix/WixToolset.Dtf.Compression.dll
Binary file not shown.
Binary file added build/wix/WixToolset.Dtf.Resources.dll
Binary file not shown.
Binary file not shown.
Binary file added build/wix/WixToolset.Dtf.WindowsInstaller.dll
Binary file not shown.
Binary file added build/wix/WixToolset.Extensibility.dll
Binary file not shown.
Binary file added build/wix/WixUIExtension.dll
Binary file not shown.
Binary file added build/wix/WixUtilExtension.dll
Binary file not shown.
Binary file added build/wix/WixVSExtension.MSBuild12.dll
Binary file not shown.
Binary file added build/wix/WixVSExtension.MSBuild14.dll
Binary file not shown.
Binary file added build/wix/WixVSExtension.dll
Binary file not shown.
Binary file added build/wix/candle.exe
Binary file not shown.
9 changes: 9 additions & 0 deletions build/wix/candle.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->


<configuration>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
Binary file added build/wix/darice.cub
Binary file not shown.
Binary file added build/wix/dark.exe
Binary file not shown.
12 changes: 12 additions & 0 deletions build/wix/dark.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->


<configuration>
<appSettings>
<add key="extensions" value="WixDifxAppExtension;WixDependencyExtension;WixDirectXExtension;WixFirewallExtension;WixGamingExtension;WixHttpExtension;WixIIsExtension;WixNetFxExtension;WixSqlExtension;WixUIExtension;WixUtilExtension;WixVSExtension" />
</appSettings>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
Binary file added build/wix/difxapp_x64.wixlib
Binary file not shown.
Binary file added build/wix/difxapp_x86.wixlib
Binary file not shown.
Binary file added build/wix/doc/DTF.chm
Binary file not shown.
Binary file added build/wix/doc/DTFAPI.chm
Binary file not shown.
Loading

0 comments on commit 5510502

Please sign in to comment.