Skip to content

gamb/postgresql-migrations

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Support me

Simple Schema Migrations for PostgreSQL

About

This repository, which began as a simple Gist, provides a tiny starter kit and instructions for safely performing schema migrations on a PostgreSQL database. It works by providing a PLPGSQL procedure which can execute a chunk of SQL and then note it as having been executed, so that it will not be executed again the next time.

We're actively using this in production over at NEC Smart Cities with great success, so it is now somewhat proven and maintained.

Installation

Copy migrations.sql to your project. Add migrations to the end of that file in the form of calls to apply_migration, as shown in the examples in that file. To apply all pending migrations, including bootstrapping the migration function and its migrations table, run the file against your database in a single transaction with psql, or via your database connection adaptor.

psql -v ON_ERROR_STOP=1 -1f -- migrations.sql yourdbname

You should generally arrange to run migrations as the database owner (or even the super-user), and your applications should use less-privileged users.

Author

This software was written by Steve Purcell.

License and copyright

MIT license.


Support this project and my other Open Source work

sanityinc.com

@sanityinc

About

Simple Schema Migrations for PostgreSQL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PLpgSQL 61.1%
  • Shell 35.7%
  • Emacs Lisp 3.2%