handle the case pg_trgm is already loaded
This commit is contained in:
parent
da0ddd5a34
commit
981f6ecfb2
|
@ -8,7 +8,8 @@ Create Date: 2021-08-20 12:11:57.901994
|
||||||
import sqlalchemy_utils
|
import sqlalchemy_utils
|
||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from psycopg2 import errors
|
||||||
|
from psycopg2.errorcodes import DUPLICATE_OBJECT
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = '424808e1fe49'
|
revision = '424808e1fe49'
|
||||||
|
@ -19,7 +20,14 @@ depends_on = None
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
op.execute('CREATE EXTENSION pg_trgm')
|
try:
|
||||||
|
op.execute('CREATE EXTENSION pg_trgm')
|
||||||
|
# thanks to https://stackoverflow.com/a/58743364/1428034 !
|
||||||
|
except sa.exc.ProgrammingError as e:
|
||||||
|
if isinstance(e.orig, errors.lookup(DUPLICATE_OBJECT)):
|
||||||
|
print(">>> pg_trgm already loaded, ignore")
|
||||||
|
op.execute("Rollback")
|
||||||
|
|
||||||
op.create_index('note_pg_trgm_index', 'alias', ['note'], unique=False, postgresql_ops={'note': 'gin_trgm_ops'}, postgresql_using='gin')
|
op.create_index('note_pg_trgm_index', 'alias', ['note'], unique=False, postgresql_ops={'note': 'gin_trgm_ops'}, postgresql_using='gin')
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue