Update README
This commit is contained in:
parent
8c519a6d56
commit
77e29e0475
49
README.rst
49
README.rst
|
@ -89,12 +89,48 @@ Testing
|
|||
|
||||
Migrations
|
||||
**********
|
||||
At this stage, migrations are created manually. To create a revision file
|
||||
execute:
|
||||
At this stage, migration files are created manually. To apply the migrations we follow
|
||||
a hybrid approach.
|
||||
|
||||
* When a schema is to be created in the db we create a revision file holding **all** the
|
||||
necessary table definitions. For example have a look on the migration file holding the initial
|
||||
declarations. There you see a full list of tables to be created. You just need to specify
|
||||
the env variable **dhi**. To create a revision file execute:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ alembic revision -m "This is migration name"
|
||||
$ alembic revision -m "My initial base revision"
|
||||
|
||||
Then run
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ export dhi=dbtest; dh inv add --common --name dbtest
|
||||
|
||||
This command will create the schemas, tables in the specified database and will stamp the
|
||||
migration file you have created as the base schema for future migrations. For more info
|
||||
in migration stamping please see [here](https://alembic.sqlalchemy.org/en/latest/cookbook.html)
|
||||
|
||||
Whenever you want to create a new schema just create a new revision with:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ alembic revision -m "My new base revision"
|
||||
|
||||
and add there **all** the tables that the new database will have. Next, you can add the
|
||||
new inventory and stamp the revision as the new base.
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ export dhi=dbtest; dh inv add --name dbtest
|
||||
|
||||
|
||||
* When you want to alter a table, column or perform another operation on tables, create
|
||||
a revision file
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ alembic revision -m "A table change"
|
||||
|
||||
Then edit the generated file with the necessary operations to perform the migration.
|
||||
Apply migrations using:
|
||||
|
@ -103,6 +139,13 @@ Apply migrations using:
|
|||
|
||||
$ alembic upgrade head
|
||||
|
||||
* Whenever you to see a full list of migrations use
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ alembic history
|
||||
|
||||
|
||||
Generating the docs
|
||||
*******************
|
||||
|
||||
|
|
74
alembic.ini
Normal file
74
alembic.ini
Normal file
|
@ -0,0 +1,74 @@
|
|||
# A generic, single database configuration.
|
||||
|
||||
[alembic]
|
||||
# path to migration scripts
|
||||
script_location = ereuse_devicehub/migrations
|
||||
|
||||
# template used to generate migration files
|
||||
# file_template = %%(rev)s_%%(slug)s
|
||||
|
||||
# timezone to use when rendering the date
|
||||
# within the migration file as well as the filename.
|
||||
# string value is passed to dateutil.tz.gettz()
|
||||
# leave blank for localtime
|
||||
# timezone =
|
||||
|
||||
# max length of characters to apply to the
|
||||
# "slug" field
|
||||
#truncate_slug_length = 40
|
||||
|
||||
# set to 'true' to run the environment during
|
||||
# the 'revision' command, regardless of autogenerate
|
||||
# revision_environment = false
|
||||
|
||||
# set to 'true' to allow .pyc and .pyo files without
|
||||
# a source .py file to be detected as revisions in the
|
||||
# versions/ directory
|
||||
# sourceless = false
|
||||
|
||||
# version location specification; this defaults
|
||||
# to alembic/versions. When using multiple version
|
||||
# directories, initial revisions must be specified with --version-path
|
||||
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
|
||||
|
||||
# the output encoding used when revision files
|
||||
# are written from script.py.mako
|
||||
# output_encoding = utf-8
|
||||
|
||||
sqlalchemy.url = driver://user:pass@localhost/dbname
|
||||
|
||||
|
||||
# Logging configuration
|
||||
[loggers]
|
||||
keys = root,sqlalchemy,alembic
|
||||
|
||||
[handlers]
|
||||
keys = console
|
||||
|
||||
[formatters]
|
||||
keys = generic
|
||||
|
||||
[logger_root]
|
||||
level = WARN
|
||||
handlers = console
|
||||
qualname =
|
||||
|
||||
[logger_sqlalchemy]
|
||||
level = WARN
|
||||
handlers =
|
||||
qualname = sqlalchemy.engine
|
||||
|
||||
[logger_alembic]
|
||||
level = INFO
|
||||
handlers =
|
||||
qualname = alembic
|
||||
|
||||
[handler_console]
|
||||
class = StreamHandler
|
||||
args = (sys.stderr,)
|
||||
level = NOTSET
|
||||
formatter = generic
|
||||
|
||||
[formatter_generic]
|
||||
format = %(levelname)-5.5s [%(name)s] %(message)s
|
||||
datefmt = %H:%M:%S
|
1140
ereuse_devicehub/migrations/versions/fbb7e2a0cde0_initial.py
Normal file
1140
ereuse_devicehub/migrations/versions/fbb7e2a0cde0_initial.py
Normal file
File diff suppressed because one or more lines are too long
Reference in a new issue