Open ramusus opened 10 years ago
And for Postgres DB I recommend to create partial indexes by putting file {{ MODEL_LOWLETTERS }}.postgresql_psycopg2.sql to sql directory of the application with content
--{{ M2M_TABLE }}
CREATE UNIQUE INDEX {{ M2M_TABLE }}_time_from_3col_uniq
ON {{ M2M_TABLE }} ({{ MODEL_LOWLETTERS }}_id, user_id, time_from)
WHERE time_from IS NOT NULL;
CREATE UNIQUE INDEX {{ M2M_TABLE }}_time_from_2col_uniq
ON {{ M2M_TABLE }} ({{ MODEL_LOWLETTERS }}_id, user_id)
WHERE time_from IS NULL;
CREATE UNIQUE INDEX {{ M2M_TABLE }}_time_to_3col_uniq
ON {{ M2M_TABLE }} ({{ MODEL_LOWLETTERS }}_id, user_id, time_to)
WHERE time_to IS NOT NULL;
CREATE UNIQUE INDEX {{ M2M_TABLE }}_time_to_2col_uniq
ON {{ M2M_TABLE }} ({{ MODEL_LOWLETTERS }}_id, user_id)
WHERE time_to IS NULL;
Don't forget to substitute {{ M2M_TABLE }} and {{ MODEL_LOWLETTERS }} variables to real values
Now migration from built-in ManyToManyField to ManyToManyHistoryField possible via south http://south.aeracode.org/ only by writing migration by hands:
Don't forget to substitute {{ M2M_TABLE }}, {{ MODEL }}, {{ FIELD }} variables to real values