{"id":23626296,"url":"https://github.com/datalust/piggy","last_synced_at":"2025-10-29T06:51:19.526Z","repository":{"id":22999647,"uuid":"97665555","full_name":"datalust/piggy","owner":"datalust","description":"A friendly PostgreSQL script runner in the spirit of DbUp.","archived":false,"fork":false,"pushed_at":"2024-06-17T04:51:38.000Z","size":11381,"stargazers_count":79,"open_issues_count":3,"forks_count":10,"subscribers_count":9,"default_branch":"dev","last_synced_at":"2025-04-10T01:12:46.606Z","etag":null,"topics":["migrator","postgres","postgresql","schema-migrations"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datalust.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-19T02:47:03.000Z","updated_at":"2025-03-29T16:06:15.000Z","dependencies_parsed_at":"2024-05-10T05:23:55.202Z","dependency_job_id":"2044b347-4912-4a69-b04a-962c4a63b830","html_url":"https://github.com/datalust/piggy","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datalust%2Fpiggy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datalust%2Fpiggy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datalust%2Fpiggy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datalust%2Fpiggy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datalust","download_url":"https://codeload.github.com/datalust/piggy/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137891,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["migrator","postgres","postgresql","schema-migrations"],"created_at":"2024-12-27T22:52:50.203Z","updated_at":"2025-10-29T06:51:14.490Z","avatar_url":"https://github.com/datalust.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Piggy](https://raw.githubusercontent.com/datalust/piggy/master/asset/Piggy-400px.png)\n\nA friendly PostgreSQL script runner in the spirit of [DbUp](https://github.com/DbUp/DbUp).\n\n[![Build status](https://ci.appveyor.com/api/projects/status/889gkdpvjbjuhkfg?svg=true)](https://ci.appveyor.com/project/datalust/piggy)\n\n### What is Piggy?\n\nPiggy 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.\n\n### Installation\n\nPiggy is available as a .NET tool package, as standalone binaries, and as a C\u0026sharp; library that can be used directly in .NET applications.\n\n#### `dotnet tool`\n\nPiggy is distributed as a [.NET tool package called _Datalust.Piggy.Cli_](https://nuget.org/packages/datalust.piggy.cli), which can be installed using:\n\n```\ndotnet tool install --global Datalust.Piggy.Cli\n```\n\nThe executable is called `piggy`. Test that the installation was successful with:\n\n```\npiggy --version\n```\n\n#### Executable binaries\n\nPre-built, native, self-contained Piggy binaries are available for Windows, macOS and Linux from [the releases page](https://github.com/datalust/piggy/releases). If your platform of choice isn't listed, please [raise an issue here](https://github.com/datalust/piggy/issues) so that we can add it.\n\n#### C# library\n\nFor development and test automation purposes, the core script runner is also packaged as a C\u0026sharp; API and [published to NuGet as _Datalust.Piggy_](https://nuget.org/packages/datalust.piggy).\n\n```csharp\n// dotnet add package Datalust.Piggy\nvar connectionString = // Npgsql connection string\nusing (var connection = DatabaseConnector.Connect(connectionString))\n{\n    UpdateSession.ApplyChangeScripts(connection, \"./db\", new Dictionary\u003cstring, string\u003e());\n}\n```\n\n### Workflow\n\nTo manage database updates with Piggy, write SQL scripts to make changes, rather than applying changes directly.\n\nOrganize change scripts on the file system under a _script root_ directory. Name files so that they sort lexicographically in the order in which they need to be executed:\n\n```\n001-create-schema.sql\n002-create-users-table.sql\n003-...\n```\n\nIf the scripts are arranged in subdirectories, these must be ordered by name as well:\n\n```\nv1/\n  001-create-schema.sql\n  002-create-users-table.sql\n  003-...\nv2/\n  001-rename-users-table.sql\n```\n\nPiggy enumerates `.sql` files and generates names like `/v1/001-create-schema.sql` using each script's filename relative to the script root. These relative names are checked against the change log table to determine which of them need to be run.\n\nTo bring a database up to date, run `piggy up`, providing the script root, host, database name, username and password:\n\n```\npiggy up -s \u003cscripts\u003e -h \u003chost\u003e -d \u003cdatabase\u003e -u \u003cusername\u003e -p \u003cpassword\u003e\n```\n\nIf the database does not exist, Piggy will create it using sensible defaults. To opt out of this behavior, add the `--no-create` flag.\n\nOver time, as your application grows, create new scripts to move the database forwards - don't edit the existing ones, since they've already been applied and will be ignored by Piggy.\n\nPiggy can be used to update from any previous schema version to the current one: scripts that have already been run on a database are ignored, so only necessary scripts are applied.\n\nFor more detailed usage information, run `piggy help up`; to see all available commands run `piggy help`.\n\n### Transactions\n\nPiggy 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:\n\n```sql\n-- PIGGY NO TRANSACTION\n```\n\nas the first line of the script.\n\n### Variable substitution\n\nPiggy uses `$var$` syntax for replaced variables:\n\n```sql\ncreate table $schema$.users (name varchar(140) not null);\ninsert into $schema$.users (name) values ('$admin$');\n```\n\nValues 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).\n\nVariables are supplied on the command-line with the `-v` flag:\n\n```\npiggy up ... -v schema=myapp -v admin=myuser\n```\n\n### Change log\n\nThe change log is stored in the target database in `piggy.changes`. The `piggy log` command is used to view applied change scripts.\n\n### Help\n\nRun `piggy help` to see all available commands, and `piggy help \u003ccommand\u003e` for detailed command help.\n\n```\n\u003e piggy help\nUsage: piggy \u003ccommand\u003e [\u003cargs\u003e]\n\nAvailable commands are:\n  baseline   Add scripts to the change log without running them\n  help       Show information about available commands\n  log        List change scripts that have been applied to a database\n  pending    Determine which scripts will be run in an update\n  up         Bring a database up to date\n  --version  Print the current executable version\n\nType `piggy help \u003ccommand\u003e` for detailed help\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatalust%2Fpiggy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatalust%2Fpiggy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatalust%2Fpiggy/lists"}