Discussion:
Using a 3rd Party Dialect
Daniel Son
2014-10-31 20:34:18 UTC
Permalink
Hi,
I'm new to SQLalchemy and alembic and I'm doing a proof of concept for
migrations in Redshift.

Initially, using the regular postgresql dialect everything is fine.
But when I try to use the redshift_sqlalchemy dialect for the last bit of
Redshift functionality, it goes caput.
And I've looked over SQLAlchemy and Alembic docs for any help on using 3rd
Party dialects and I can't seem to get anywhere.

Environment:
The basic setup as told by the Tutorial

The following are installed in a virtualenv:
pip install alembic
pip install psycopg2
pip install redshift_sqlalchemy

I've tried to manually register the dialect:
from sqlalchemy.dialects import registry
registry.register("redshift", "redshift_sqlalchemy.dialect",
"RedshiftDialect")
registry.register("redshift.psycopg2", "redshift_sqlalchemy.dialect",
"RedshiftDialect")

And tried the following url setups in my alembic.ini (via alembic init)
sqlalchemy.url = redshift+psycopg2://user:***@host:port/dbname
sqlalchemy.url = redshift://user:***@host:port/dbname

Both error out the same as this trace out.

Traceback (most recent call last):
File "/opt/virtualenvs/alembic/bin/alembic", line 9, in <module>
load_entry_point('alembic==0.6.7', 'console_scripts', 'alembic')()
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py",
line 306, in main
CommandLine(prog=prog).main(argv=argv)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py",
line 300, in main
self.run_cmd(cfg, options)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py",
line 286, in run_cmd
**dict((k, getattr(options, k)) for k in kwarg)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/command.py",
line 129, in upgrade
script.run_env()
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/script.py",
line 208, in run_env
util.load_python_file(self.dir, 'env.py')
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/util.py",
line 230, in load_python_file
module = load_module_py(module_id, path)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/compat.py",
line 63, in load_module_py
mod = imp.load_source(module_id, path, fp)
File "dson_test/env.py", line 92, in <module>
run_migrations_online()
File "dson_test/env.py", line 80, in run_migrations_online
target_metadata=target_metadata
File "<string>", line 7, in configure
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/environment.py",
line 672, in configure
opts=opts
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/migration.py",
line 158, in configure
return MigrationContext(dialect, connection, opts, environment_context)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/migration.py",
line 103, in __init__
self.impl = ddl.DefaultImpl.get_by_dialect(dialect)(
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/ddl/impl.py",
line 55, in get_by_dialect
return _impls[dialect.name]
KeyError: 'redshift'

What am I missing?

Thanks,
Daniel
--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Bayer
2014-11-01 14:40:01 UTC
Permalink
alembic doesn’t have a formally published extension API as of yet, to get that to work you’d need to make an Impl:


from alembic.ddl.postgresql import PostgresqlImpl

class RedshiftImpl(PostgresqlImpl):
__dialect__ = ‘redshift’


that will register the name “redshift” into alembic’s lookup.
Hi,
I'm new to SQLalchemy and alembic and I'm doing a proof of concept for migrations in Redshift.
Initially, using the regular postgresql dialect everything is fine.
But when I try to use the redshift_sqlalchemy dialect for the last bit of Redshift functionality, it goes caput.
And I've looked over SQLAlchemy and Alembic docs for any help on using 3rd Party dialects and I can't seem to get anywhere.
The basic setup as told by the Tutorial
pip install alembic
pip install psycopg2
pip install redshift_sqlalchemy
from sqlalchemy.dialects import registry
registry.register("redshift", "redshift_sqlalchemy.dialect", "RedshiftDialect")
registry.register("redshift.psycopg2", "redshift_sqlalchemy.dialect", "RedshiftDialect")
And tried the following url setups in my alembic.ini (via alembic init)
Both error out the same as this trace out.
File "/opt/virtualenvs/alembic/bin/alembic", line 9, in <module>
load_entry_point('alembic==0.6.7', 'console_scripts', 'alembic')()
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py", line 306, in main
CommandLine(prog=prog).main(argv=argv)
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py", line 300, in main
self.run_cmd(cfg, options)
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py", line 286, in run_cmd
**dict((k, getattr(options, k)) for k in kwarg)
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/command.py", line 129, in upgrade
script.run_env()
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/script.py", line 208, in run_env
util.load_python_file(self.dir, 'env.py')
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/util.py", line 230, in load_python_file
module = load_module_py(module_id, path)
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/compat.py", line 63, in load_module_py
mod = imp.load_source(module_id, path, fp)
File "dson_test/env.py", line 92, in <module>
run_migrations_online()
File "dson_test/env.py", line 80, in run_migrations_online
target_metadata=target_metadata
File "<string>", line 7, in configure
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/environment.py", line 672, in configure
opts=opts
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/migration.py", line 158, in configure
return MigrationContext(dialect, connection, opts, environment_context)
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/migration.py", line 103, in __init__
self.impl = ddl.DefaultImpl.get_by_dialect(dialect)(
File "/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/ddl/impl.py", line 55, in get_by_dialect
return _impls[dialect.name]
KeyError: 'redshift'
What am I missing?
Thanks,
Daniel
--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kayvon Raphael
2017-03-10 18:42:24 UTC
Permalink
Hi there - is there a specific place to add that class so that it gets
picked up by alembic? Added to env.py but did not get registered

Thanks
Post by Michael Bayer
alembic doesn’t have a formally published extension API as of yet, to get
from alembic.ddl.postgresql import PostgresqlImpl
__dialect__ = ‘redshift’
that will register the name “redshift” into alembic’s lookup.
Hi,
I'm new to SQLalchemy and alembic and I'm doing a proof of concept for
migrations in Redshift.
Initially, using the regular postgresql dialect everything is fine.
But when I try to use the redshift_sqlalchemy dialect for the last bit of
Redshift functionality, it goes caput.
And I've looked over SQLAlchemy and Alembic docs for any help on using 3rd
Party dialects and I can't seem to get anywhere.
The basic setup as told by the Tutorial
pip install alembic
pip install psycopg2
pip install redshift_sqlalchemy
from sqlalchemy.dialects import registry
registry.register("redshift", "redshift_sqlalchemy.dialect",
"RedshiftDialect")
registry.register("redshift.psycopg2", "redshift_sqlalchemy.dialect", "RedshiftDialect")
And tried the following url setups in my alembic.ini (via alembic init)
Both error out the same as this trace out.
File "/opt/virtualenvs/alembic/bin/alembic", line 9, in <module>
load_entry_point('alembic==0.6.7', 'console_scripts', 'alembic')()
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py",
line 306, in main
CommandLine(prog=prog).main(argv=argv)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py",
line 300, in main
self.run_cmd(cfg, options)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py",
line 286, in run_cmd
**dict((k, getattr(options, k)) for k in kwarg)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/command.py",
line 129, in upgrade
script.run_env()
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/script.py",
line 208, in run_env
util.load_python_file(self.dir, 'env.py')
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/util.py",
line 230, in load_python_file
module = load_module_py(module_id, path)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/compat.py",
line 63, in load_module_py
mod = imp.load_source(module_id, path, fp)
File "dson_test/env.py", line 92, in <module>
run_migrations_online()
File "dson_test/env.py", line 80, in run_migrations_online
target_metadata=target_metadata
File "<string>", line 7, in configure
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/environment.py",
line 672, in configure
opts=opts
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/migration.py",
line 158, in configure
return MigrationContext(dialect, connection, opts, environment_context)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/migration.py",
line 103, in __init__
self.impl = ddl.DefaultImpl.get_by_dialect(dialect)(
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/ddl/impl.py",
line 55, in get_by_dialect
return _impls[dialect.name]
KeyError: 'redshift'
What am I missing?
Thanks,
Daniel
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
mike bayer
2017-03-10 19:56:20 UTC
Permalink
env.py is the place to put it, because Alembic commands will run env.py
at the start of an operation (assuming it's an operation for which the
environment is started up) and the class definition will immediately
register the dialect.

Feel free to provide more specifics what commands you're running and
what symptoms of "not registered" you're seeing.
Post by Kayvon Raphael
Hi there - is there a specific place to add that class so that it gets
picked up by alembic? Added to env.py but did not get registered
Thanks
alembic doesn’t have a formally published extension API as of yet,
from alembic.ddl.postgresql import PostgresqlImpl
__dialect__ = ‘redshift’
that will register the name “redshift” into alembic’s lookup.
Post by Daniel Son
Hi,
I'm new to SQLalchemy and alembic and I'm doing a proof of concept
for migrations in Redshift.
Initially, using the regular postgresql dialect everything is fine.
But when I try to use the redshift_sqlalchemy dialect for the last
bit of Redshift functionality, it goes caput.
And I've looked over SQLAlchemy and Alembic docs for any help on
using 3rd Party dialects and I can't seem to get anywhere.
The basic setup as told by the Tutorial
pip install alembic
pip install psycopg2
pip install redshift_sqlalchemy
from sqlalchemy.dialects import registry
registry.register("redshift", "redshift_sqlalchemy.dialect", "RedshiftDialect")
registry.register("redshift.psycopg2",
"redshift_sqlalchemy.dialect", "RedshiftDialect")
And tried the following url setups in my alembic.ini (via alembic init)
Both error out the same as this trace out.
File "/opt/virtualenvs/alembic/bin/alembic", line 9, in <module>
load_entry_point('alembic==0.6.7', 'console_scripts', 'alembic')()
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py",
line 306, in main
CommandLine(prog=prog).main(argv=argv)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py",
line 300, in main
self.run_cmd(cfg, options)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/config.py",
line 286, in run_cmd
**dict((k, getattr(options, k)) for k in kwarg)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/command.py",
line 129, in upgrade
script.run_env()
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/script.py",
line 208, in run_env
util.load_python_file(self.dir, 'env.py')
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/util.py",
line 230, in load_python_file
module = load_module_py(module_id, path)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/compat.py",
line 63, in load_module_py
mod = imp.load_source(module_id, path, fp)
File "dson_test/env.py", line 92, in <module>
run_migrations_online()
File "dson_test/env.py", line 80, in run_migrations_online
target_metadata=target_metadata
File "<string>", line 7, in configure
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/environment.py",
line 672, in configure
opts=opts
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/migration.py",
line 158, in configure
return MigrationContext(dialect, connection, opts,
environment_context)
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/migration.py",
line 103, in __init__
self.impl = ddl.DefaultImpl.get_by_dialect(dialect)(
File
"/opt/virtualenvs/alembic/lib/python2.7/site-packages/alembic/ddl/impl.py",
line 55, in get_by_dialect
return _impls[dialect.name <http://dialect.name>]
KeyError: 'redshift'
What am I missing?
Thanks,
Daniel
--
You received this message because you are subscribed to the Google
Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it,
<javascript:>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google
Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...