2013-10-22 22:15:48 +08:00
cartodb-postgresql
==================
2014-05-08 23:24:17 +08:00
[![Build Status ](http://travis-ci.org/CartoDB/cartodb-postgresql.png )]
(http://travis-ci.org/CartoDB/cartodb-postgresql)
2013-10-22 22:15:48 +08:00
PostgreSQL extension for CartoDB
2013-10-22 22:13:17 +08:00
2013-10-22 23:11:02 +08:00
See https://github.com/CartoDB/cartodb/wiki/CartoDB-PostgreSQL-extension
2014-05-06 16:36:07 +08:00
Dependencies
2013-10-22 22:13:17 +08:00
------------
* PostgreSQL 9.3+
2014-05-06 17:11:49 +08:00
* [Schema triggers extension]
(https://bitbucket.org/malloclabs/pg_schema_triggers)
2014-06-03 22:26:05 +08:00
(or [fork ](https://github.com/CartoDB/pg_schema_triggers ))
2014-05-06 17:11:49 +08:00
Install
-------
make all install
Test installation
-----------------
make installcheck
NOTE: if ``test_ddl_triggers`` fails it's likely due to an incomplete
installation of schema_triggers: you need to add ``schema_triggers.so``
to the ``shared_preload_libraries`` setting in postgresql.conf !
2014-05-08 00:12:43 +08:00
Enable database
---------------
2014-05-06 17:11:49 +08:00
2014-05-08 00:12:43 +08:00
In a database that needs to be turned into a "cartodb" user database, run:
2014-05-06 17:11:49 +08:00
```sql
2014-05-08 00:12:43 +08:00
CREATE EXTENSION postgis;
CREATE EXTENSION schema_triggers;
CREATE EXTENSION cartodb;
```
Migrate existing cartodb database
---------------------------------
When upgrading an existing cartodb user database, the cartodb extension
can be migrated from the "unpackaged" version. The procedure will copy
the data from ``public.CDB_TableMetada`` to ``cartodb.CDB_TableMetadata``,
re-cartodbfy all tables using old functions in triggers and drop the
cartodb functions from the 'public' schema. All new cartodb objects will
be in the "cartodb" schema.
```sql
2014-05-09 01:01:32 +08:00
CREATE EXTENSION postgis FROM unpackaged;
CREATE EXTENSION schema_triggers;
2014-05-08 00:12:43 +08:00
CREATE EXTENSION cartodb FROM unpackaged;
2014-05-06 17:11:49 +08:00
```
2014-06-04 16:13:35 +08:00
Update cartodb extension
------------------------
Updating the version of cartodb extension installed in a database
is done using ALTER EXTENSION.
```sql
ALTER EXTENSION cartodb UPDATE TO '0.1.1';
```
2014-06-04 16:16:42 +08:00
The target version needs to be installed on the system first
(see Install section).
2014-06-04 16:13:35 +08:00
If the "TO 'x.y.z'" part is omitted, the extension will be updated to the
latest installed version, which you can find with the following command:
```sh
grep default_version `pg_config --sharedir` /extension/cartodb.control
```
Updates are performed by PostgreSQL by loading one or more migration scripts
as needed to go from the installed version S to the target version T.
All migration scripts are in the "extension" directory of PostgreSQL:
```sh
ls `pg_config --sharedir` /extension/cartodb*
```
During development the cartodb extension version doesn't change with
every commit, so testing latest change requires cheating with PostgreSQL
so to enforce re-load of the scripts. To help with cheating, "make install"
also installs migration scripts to go from "V" to "V"next and from "V"next
to "V". Example to upgrade a 0.2.0dev version:
```sql
ALTER EXTENSION cartodb UPDATE TO '0.2.0devnext';
ALTER EXTENSION cartodb UPDATE TO '0.2.0dev';
```
2014-06-04 16:28:48 +08:00
Starting with 0.2.0, the in-place reload can be done with an ad-hoc function:
```sql
SELECT cartodb.cdb_extension_reload();
```
2014-06-04 18:44:37 +08:00
Troubleshooting
---------------
### Mac OS X sed
Mac OS X comes with sed from FreeBSD, some scripting in Makefile is incompatible with that version of sed so we recommend you to install GNU sed. The easiest way is via [Homebrew ](http://brew.sh/ ) like in:
```sh
brew install gnu-sed --default-names
```