Skip to main content

Simple tool for managing DB structure, automating patch creation for DB structure migration.

Project description

sqlibrist
=========

Sqlibrist is made for developers, who do not use ORM to manage their database
structure. Programming database entities and deploying them to production
is not easy. Naive approach is to manually write patches with SQL statements and then replay
them on others DB instances. This, being simple and straightforward, may get tricky
when your database structure grows in size and have numerous inter-dependent
objects.

Sqlibrist makes the process of creating SQL patches much more easy and proposes
a way to organize your SQL code. All database objects are described declaratively
in separate files in the form of `CREATE TABLE` or `CREATE FUNCTION`, having
dependency instructions.

The whole thing is inspired by Sqitch (see Alternatives below) and Django Migrations (may be you
remember Django South). Every time you invoke `makemigration` command, snapshot
of current scheme is made and compared with previous snapshot. Then, SQL patch
is created with instructions to recreate all changed objects cascadely with their
dependencies, create new or remove deleted. In the latter case, sqlibrist will not
let you delete object that has left dependants.




Requirements
============

Python dependencies:

- PyYAML
- psycopg2 (optional)
- mysql-python (optional)

Installation
============

Sqlibrist can be installed into virtualenv:

$ pip install sqlibrist

or system-wide:

$ sudo pip install sqlibrist

Please, note: MySQL or PostgreSQL connectivity support is installed separately.
Make sure you have DB client dev packages:

$ sudo apt-get install libmysqlclient-dev # MySQL

or

$ sudo apt-get install libpq-dev # PostgreSQL


Tutorial
========

Let's create simple project and go through typical steps of DB schema manageent.
This will be small webshop.

Create empty directory:

$ mkdir shop_schema
$ cd shop_schema

Then we need to create sqlibrist database structure, where we will keep
schema and migrations.

$ sqlibrist init



Django integration
==================

Sqlibrist has a very small application to integrate itself into your Django
project and access DB configuration.

Installation
------------

Add `'django_sqlibrist'` to INSTALLED_APPS

Settings
--------

`SQLIBRIST_DIRECTORY` - Path to the directory with schema and migrations files.
Defaults to project's BASE_DIR/sql

Usage
-----

$ python manage.py sqlibrist <command> [options]

If you want your tables to be accessible from Django ORM and/or for using
Django Admin for these tables, add following attributes to the model's Meta class:

class SomeTable(models.Model):
field1 = models.CharField()
...
class Meta:
managed = False # will tell Django to not create migrations for that table
table_name = 'sometable' # name of your table

If primary key has other name than `id` and type not Integer, add that field to
model class with `primary_key=True` argument, for example:

my_key = models.IntegerField(primary_key=True)



Migrating existing models
-------------------------



Alternatives
============

Sqlibrist is not new concept, it has a lot of alternatives, most notable, I think,
is [sqitch](http://sqitch.org/). It is great tool, with rich development history and
community arount it. I started using it at first, however it did not make me completely
happy. My problem with sqitch was pretty hard installation progress
(shame on me, first of all). It is written in Perl and has huge number of dependencies.
For man, unfamiliar with Perl pachage systems, it was quite a challenge to
install sqitch on 3 different Linux distributions: Fedora, Ubuntu and Arch.
In addition, I found sqitch's dependency tracking being complicated and unobvious
to perform relatively simple schema changes. Don't get me wrong - I am not
advocating you against using sqitch, you should try it yourself.


Changelog
=========

0.0.6 django_sqlibrist moved to separate package and is importable in settings.py as "django_sqlibrist"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlibrist-0.0.7.tar.gz (10.7 kB view details)

Uploaded Source

File details

Details for the file sqlibrist-0.0.7.tar.gz.

File metadata

  • Download URL: sqlibrist-0.0.7.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sqlibrist-0.0.7.tar.gz
Algorithm Hash digest
SHA256 d38c4d291d3b5f32579d7cda31ad80345975df6a21e5911f49f7e2b11e3043ab
MD5 520cc7ad99b5f72993a5324589d5b1bb
BLAKE2b-256 1e8d63093f13b174c87f1738e9fde88cdfbc43965fb206f3a391ee46e9ba25a5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page