Fix problems with DB initialization on SQLite
[mygpo.git] / mygpo / podcasts / migrations / 0024_episodes_index.py
blob730511015da470a1d91f5dbece40e45d579b0912
1 # -*- coding: utf-8 -*-
4 from django.db import migrations
7 def forward(apps, schema_editor):
9 # This index can apparently not be created on sqlite
10 # As it is not recommended for production use, we can just
11 # skip the index there
12 if schema_editor.connection.vendor == 'sqlite':
13 return
15 migrations.RunSQL(
16 sql=[
17 ('CREATE INDEX episodes_podcast_hasreleased '
18 'ON podcasts_episode '
19 '(podcast_id, (released IS NOT NULL) DESC, released DESC);',
20 None)
25 def reverse(apps, schema_editor):
26 migrations.RunSQL([
27 ('DROP INDEX IF EXISTS episodes_podcast_hasreleased;', None)
31 class Migration(migrations.Migration):
33 dependencies = [
34 ('podcasts', '0023_auto_20140729_1711'),
37 operations = [
38 # Wrap RunSQL in RunPython to check for DB backend
39 # http://stackoverflow.com/a/37521148/693140
40 migrations.RunPython(
41 code=forward,
42 reverse_code=reverse,