Détermination du bord politique de mots divers http://clivage.foxgl.ovh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

97 lines
2.8 KiB

  1. from __future__ import with_statement
  2. import logging
  3. from logging.config import fileConfig
  4. from alembic import context
  5. from sqlalchemy import engine_from_config
  6. from sqlalchemy import pool
  7. # this is the Alembic Config object, which provides
  8. # access to the values within the .ini file in use.
  9. config = context.config
  10. # Interpret the config file for Python logging.
  11. # This line sets up loggers basically.
  12. fileConfig(config.config_file_name)
  13. logger = logging.getLogger('alembic.env')
  14. # add your model's MetaData object here
  15. # for 'autogenerate' support
  16. # from myapp import mymodel
  17. # target_metadata = mymodel.Base.metadata
  18. from flask import current_app
  19. config.set_main_option('sqlalchemy.url',
  20. current_app.config.get('SQLALCHEMY_DATABASE_URI'))
  21. target_metadata = current_app.extensions['migrate'].db.metadata
  22. # other values from the config, defined by the needs of env.py,
  23. # can be acquired:
  24. # my_important_option = config.get_main_option("my_important_option")
  25. # ... etc.
  26. def run_migrations_offline():
  27. """Run migrations in 'offline' mode.
  28. This configures the context with just a URL
  29. and not an Engine, though an Engine is acceptable
  30. here as well. By skipping the Engine creation
  31. we don't even need a DBAPI to be available.
  32. Calls to context.execute() here emit the given string to the
  33. script output.
  34. """
  35. url = config.get_main_option("sqlalchemy.url")
  36. context.configure(
  37. url=url, target_metadata=target_metadata, literal_binds=True
  38. )
  39. with context.begin_transaction():
  40. context.run_migrations()
  41. def run_migrations_online():
  42. """Run migrations in 'online' mode.
  43. In this scenario we need to create an Engine
  44. and associate a connection with the context.
  45. """
  46. # this callback is used to prevent an auto-migration from being generated
  47. # when there are no changes to the schema
  48. # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
  49. def process_revision_directives(context, revision, directives):
  50. if getattr(config.cmd_opts, 'autogenerate', False):
  51. script = directives[0]
  52. if script.upgrade_ops.is_empty():
  53. directives[:] = []
  54. logger.info('No changes in schema detected.')
  55. connectable = engine_from_config(
  56. config.get_section(config.config_ini_section),
  57. prefix='sqlalchemy.',
  58. poolclass=pool.NullPool,
  59. )
  60. with connectable.connect() as connection:
  61. context.configure(
  62. connection=connection,
  63. target_metadata=target_metadata,
  64. process_revision_directives=process_revision_directives,
  65. **current_app.extensions['migrate'].configure_args
  66. )
  67. with context.begin_transaction():
  68. context.run_migrations()
  69. if context.is_offline_mode():
  70. run_migrations_offline()
  71. else:
  72. run_migrations_online()