Skip to content

Commit d593494

Browse files
committed
Move ltree create statement out of migrations
1 parent 7c471f1 commit d593494

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

.circleci/config.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
name: Installing top-level dependencies
3636
command: |
3737
export PATH=~/.local/bin:$PATH
38-
pip install --user tox poetry
38+
pip install --user tox poetry psycopg2-binary
3939
- run:
4040
name: Waiting for Postgres to start up
4141
command: |
@@ -46,6 +46,27 @@ jobs:
4646
sleep 1
4747
done
4848
echo Failed waiting for Postgres && exit 1
49+
- run:
50+
name: Creating Postgres database and ltree extension
51+
command: |
52+
python -c "
53+
import psycopg2, os
54+
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
55+
56+
def getcur(dbname):
57+
conn = psycopg2.connect(
58+
dbname=dbname,
59+
host=os.environ['PG_HOST'],
60+
user=os.environ['PG_USER'],
61+
password=os.environ['PG_PASSWORD'],
62+
)
63+
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
64+
return conn.cursor()
65+
66+
cur = getcur('postgres')
67+
cur.execute('CREATE DATABASE \"django-pgtree-test\"')
68+
cur = getcur('django-pgtree-test')
69+
cur.execute('CREATE EXTENSION ltree')"
4970
- run:
5071
name: Running tests
5172
command: |

testproject/settings.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
"django.contrib.sessions",
3838
"django.contrib.messages",
3939
"django.contrib.staticfiles",
40-
# In this case we're creating the ltree extension in a migration,
41-
# so it needs to come before django_pgtree (which does a CREATE
42-
# FUNCTION that uses ltree in its migrations)
4340
"testproject.testapp",
4441
"django_pgtree",
4542
]
@@ -84,6 +81,7 @@
8481
"HOST": os.environ.get("PG_HOST", ""),
8582
"USER": os.environ.get("PG_USER", ""),
8683
"PASSWORD": os.environ.get("PG_PASSWORD", ""),
84+
"TEST": {"TEMPLATE": "template1", "NAME": "django-pgtree-test"},
8785
}
8886
}
8987

testproject/testapp/migrations/0001_initial.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ class Migration(migrations.Migration):
1212
dependencies = []
1313

1414
operations = [
15-
migrations.RunSQL(
16-
"CREATE EXTENSION IF NOT EXISTS ltree", migrations.RunSQL.noop
17-
),
1815
migrations.CreateModel(
1916
name="TestModel",
2017
fields=[

0 commit comments

Comments
 (0)