From 66086301a8d85444bb608e4158c15f25b5ae2cdc Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 26 Jun 2018 00:08:18 -0700 Subject: Add alembic, correct name of init script in setup.py - Adjust linenos in defining models step - Update package version numbers to latest --- docs/tutorials/wiki2/definingmodels.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/tutorials/wiki2/definingmodels.rst') diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index fd1967d99..d76959e30 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -33,7 +33,7 @@ Open ``tutorial/setup.py`` and edit it to look like the following: .. literalinclude:: src/models/setup.py :linenos: - :emphasize-lines: 12 + :emphasize-lines: 13 :language: python Only the highlighted line needs to be added. @@ -70,7 +70,7 @@ like the following. .. code-block:: text - Successfully installed bcrypt-3.1.2 cffi-1.9.1 pycparser-2.17 tutorial + Successfully installed bcrypt-3.1.4 cffi-1.11.5 pycparser-2.18 tutorial Remove ``mymodel.py`` -- cgit v1.2.3 From beeee29617d64f67f8eec2991f6b413351393c9e Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 26 Jun 2018 00:30:17 -0700 Subject: rename script to align with cookiecutter default --- docs/tutorials/wiki2/definingmodels.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'docs/tutorials/wiki2/definingmodels.rst') diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index d76959e30..9ed84ce76 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -158,11 +158,11 @@ the following: Here we align our imports with the names of the models, ``Page`` and ``User``. -Edit ``scripts/initializedb.py`` -================================ +Edit ``scripts/initialize_db.py`` +================================= We haven't looked at the details of this file yet, but within the ``scripts`` -directory of your ``tutorial`` package is a file named ``initializedb.py``. +directory of your ``tutorial`` package is a file named ``initialize_db.py``. Code in this file is executed whenever we run the ``initialize_tutorial_db`` command, as we did in the installation step of this tutorial. @@ -171,15 +171,15 @@ command, as we did in the installation step of this tutorial. The command is named ``initialize_tutorial_db`` because of the mapping defined in the ``[console_scripts]`` entry point of our project's ``setup.py`` file. Since we've changed our model, we need to make changes to our -``initializedb.py`` script. In particular, we'll replace our import of +``initialize_db.py`` script. In particular, we'll replace our import of ``MyModel`` with those of ``User`` and ``Page``. We'll also change the very end of the script to create two ``User`` objects (``basic`` and ``editor``) as well as a ``Page``, rather than a ``MyModel``, and add them to our ``dbsession``. -Open ``tutorial/scripts/initializedb.py`` and edit it to look like the +Open ``tutorial/scripts/initialize_db.py`` and edit it to look like the following: -.. literalinclude:: src/models/tutorial/scripts/initializedb.py +.. literalinclude:: src/models/tutorial/scripts/initialize_db.py :linenos: :language: python :emphasize-lines: 18,44-57 @@ -192,7 +192,7 @@ Installing the project and re-initializing the database Because our model has changed, and in order to reinitialize the database, we need to rerun the ``initialize_tutorial_db`` command to pick up the changes -we've made to both the models.py file and to the initializedb.py file. See +we've made to both the models.py file and to the initialize_db.py file. See :ref:`initialize_db_wiki2` for instructions. Success will look something like this: -- cgit v1.2.3 From 03fc543e74029978dc38eb0765f24bfe40adbc50 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 28 Jun 2018 01:22:35 -0700 Subject: Add Alembic step and overview --- docs/tutorials/wiki2/definingmodels.rst | 129 ++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'docs/tutorials/wiki2/definingmodels.rst') diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index 9ed84ce76..0fed0585c 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -158,6 +158,135 @@ the following: Here we align our imports with the names of the models, ``Page`` and ``User``. +.. _wiki2_migrate_database_alembic: + +Migrate the database with Alembic +================================= + +Now that we have written our models, we need to modify the database schema to reflect the changes to our code. Let's generate a new revision, then upgrade the database to the latest revision (head). + +On UNIX: + +.. code-block:: bash + + $ $VENV/bin/alembic -c development.ini revision --autogenerate \ + -m "use new models Page and User" + $ $VENV/bin/alembic -c development.ini upgrade head + +On Windows: + +.. code-block:: doscon + + c:\tutorial> %VENV%\Scripts\alembic -c development.ini revision \ + --autogenerate -m "use new models Page and User" + c:\tutorial> %VENV%\Scripts\alembic -c development.ini upgrade head + +Success executing these commands will generate output similar to the following. + +.. code-block:: text + + 2018-06-28 00:43:15,609 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 + 2018-06-28 00:43:15,609 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-28 00:43:15,610 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 + 2018-06-28 00:43:15,610 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-28 00:43:15,612 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA table_info("alembic_version") + 2018-06-28 00:43:15,612 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,613 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT alembic_version.version_num + FROM alembic_version + 2018-06-28 00:43:15,613 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,620 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT name FROM sqlite_master WHERE type='table' ORDER BY name + 2018-06-28 00:43:15,620 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,622 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA table_info("models") + 2018-06-28 00:43:15,622 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,623 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = 'models' AND type = 'table' + 2018-06-28 00:43:15,623 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,624 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA foreign_key_list("models") + 2018-06-28 00:43:15,624 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,624 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = 'models' AND type = 'table' + 2018-06-28 00:43:15,624 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,625 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_list("models") + 2018-06-28 00:43:15,625 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,625 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_info("my_index") + 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_list("models") + 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_info("my_index") + 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = 'models' AND type = 'table' + 2018-06-28 00:43:15,627 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + Generating //tutorial/tutorial/alembic/versions/20180628_9451789ab7d6.py ... done + +.. code-block:: text + + 2018-06-28 00:46:18,152 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 + 2018-06-28 00:46:18,153 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-28 00:46:18,153 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 + 2018-06-28 00:46:18,153 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-28 00:46:18,155 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA table_info("alembic_version") + 2018-06-28 00:46:18,155 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:46:18,155 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT alembic_version.version_num + FROM alembic_version + 2018-06-28 00:46:18,155 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:46:18,159 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] + CREATE TABLE users ( + id INTEGER NOT NULL, + name TEXT NOT NULL, + role TEXT NOT NULL, + password_hash TEXT, + CONSTRAINT pk_users PRIMARY KEY (id), + CONSTRAINT uq_users_name UNIQUE (name) + ) + + + 2018-06-28 00:46:18,159 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:46:18,160 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + 2018-06-28 00:46:18,161 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] + CREATE TABLE pages ( + id INTEGER NOT NULL, + name TEXT NOT NULL, + data TEXT NOT NULL, + creator_id INTEGER NOT NULL, + CONSTRAINT pk_pages PRIMARY KEY (id), + CONSTRAINT fk_pages_creator_id_users FOREIGN KEY(creator_id) REFERENCES users (id), + CONSTRAINT uq_pages_name UNIQUE (name) + ) + + + 2018-06-28 00:46:18,161 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:46:18,162 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + 2018-06-28 00:46:18,163 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] + DROP INDEX my_index + 2018-06-28 00:46:18,163 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:46:18,164 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + 2018-06-28 00:46:18,164 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] + DROP TABLE models + 2018-06-28 00:46:18,164 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:46:18,165 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + 2018-06-28 00:46:18,166 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] UPDATE alembic_version SET version_num='9451789ab7d6' WHERE alembic_version.version_num = 'd2f465a83563' + 2018-06-28 00:46:18,166 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-28 00:46:18,166 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + + +.. _wiki2_alembic_overview: + +Alembic overview +---------------- + +Let's briefly discuss our configuration for Alembic. + +In the alchemy cookiecutter's ``development.ini`` file, the setting for ``script_location`` configures Alembic to look for the migration script in the directory ``tutorial/alembic``. +By default Alembic stores the migration files one level deeper in ``tutorial/alembic/versions``. +These files are generated by Alembic, then executed when we run upgrade or downgrade migrations. +The setting ``file_template`` provides the format for each migration's file name. +We've configured the ``file_template`` setting to make it somewhat easy to find migrations by file name. + +At this point in this tutorial, we have two migration files. +Examine them to see what Alembic will do when you upgrade or downgrade the database to a specific revision. +Notice the revision identifiers and how they relate to one another in a chained sequence. + +.. seealso:: For further information, see the `Alembic documentation `_. + + Edit ``scripts/initialize_db.py`` ================================= -- cgit v1.2.3 From 6986c6b7a4c525144b4719a355cb6fd0053cff03 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 28 Jun 2018 01:49:21 -0700 Subject: Modify sections for db script to align with Alembic workflow (WIP) - This is not complete. I don't know what I did wrong, but the script does not run. --- docs/tutorials/wiki2/definingmodels.rst | 58 ++++----------------------------- 1 file changed, 7 insertions(+), 51 deletions(-) (limited to 'docs/tutorials/wiki2/definingmodels.rst') diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index 0fed0585c..6fb4c0c1b 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -301,8 +301,7 @@ command, as we did in the installation step of this tutorial. Since we've changed our model, we need to make changes to our ``initialize_db.py`` script. In particular, we'll replace our import of -``MyModel`` with those of ``User`` and ``Page``. We'll also change the very end -of the script to create two ``User`` objects (``basic`` and ``editor``) as well +``MyModel`` with those of ``User`` and ``Page``. We'll also change the the script to create two ``User`` objects (``basic`` and ``editor``) as well as a ``Page``, rather than a ``MyModel``, and add them to our ``dbsession``. Open ``tutorial/scripts/initialize_db.py`` and edit it to look like the @@ -316,61 +315,18 @@ following: Only the highlighted lines need to be changed. -Installing the project and re-initializing the database -======================================================= +Populating the database +======================= -Because our model has changed, and in order to reinitialize the database, we +Because our model has changed, and to repopulate the database, we need to rerun the ``initialize_tutorial_db`` command to pick up the changes -we've made to both the models.py file and to the initialize_db.py file. See -:ref:`initialize_db_wiki2` for instructions. +we've made to the initialize_db.py file. See :ref:`initialize_db_wiki2` for instructions. Success will look something like this: -.. code-block:: bash - - 2016-12-20 02:51:11,195 INFO [sqlalchemy.engine.base.Engine:1235][MainThread] SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 - 2016-12-20 02:51:11,195 INFO [sqlalchemy.engine.base.Engine:1236][MainThread] () - 2016-12-20 02:51:11,195 INFO [sqlalchemy.engine.base.Engine:1235][MainThread] SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 - 2016-12-20 02:51:11,195 INFO [sqlalchemy.engine.base.Engine:1236][MainThread] () - 2016-12-20 02:51:11,196 INFO [sqlalchemy.engine.base.Engine:1140][MainThread] PRAGMA table_info("pages") - 2016-12-20 02:51:11,196 INFO [sqlalchemy.engine.base.Engine:1143][MainThread] () - 2016-12-20 02:51:11,196 INFO [sqlalchemy.engine.base.Engine:1140][MainThread] PRAGMA table_info("users") - 2016-12-20 02:51:11,197 INFO [sqlalchemy.engine.base.Engine:1143][MainThread] () - 2016-12-20 02:51:11,197 INFO [sqlalchemy.engine.base.Engine:1140][MainThread] - CREATE TABLE users ( - id INTEGER NOT NULL, - name TEXT NOT NULL, - role TEXT NOT NULL, - password_hash TEXT, - CONSTRAINT pk_users PRIMARY KEY (id), - CONSTRAINT uq_users_name UNIQUE (name) - ) - - - 2016-12-20 02:51:11,197 INFO [sqlalchemy.engine.base.Engine:1143][MainThread] () - 2016-12-20 02:51:11,198 INFO [sqlalchemy.engine.base.Engine:719][MainThread] COMMIT - 2016-12-20 02:51:11,199 INFO [sqlalchemy.engine.base.Engine:1140][MainThread] - CREATE TABLE pages ( - id INTEGER NOT NULL, - name TEXT NOT NULL, - data TEXT NOT NULL, - creator_id INTEGER NOT NULL, - CONSTRAINT pk_pages PRIMARY KEY (id), - CONSTRAINT uq_pages_name UNIQUE (name), - CONSTRAINT fk_pages_creator_id_users FOREIGN KEY(creator_id) REFERENCES users (id) - ) - +.. code-block:: text - 2016-12-20 02:51:11,199 INFO [sqlalchemy.engine.base.Engine:1143][MainThread] () - 2016-12-20 02:51:11,200 INFO [sqlalchemy.engine.base.Engine:719][MainThread] COMMIT - 2016-12-20 02:51:11,755 INFO [sqlalchemy.engine.base.Engine:679][MainThread] BEGIN (implicit) - 2016-12-20 02:51:11,755 INFO [sqlalchemy.engine.base.Engine:1140][MainThread] INSERT INTO users (name, role, password_hash) VALUES (?, ?, ?) - 2016-12-20 02:51:11,755 INFO [sqlalchemy.engine.base.Engine:1143][MainThread] ('editor', 'editor', '$2b$12$ds7h2Zb7.l6TEFup5h8f4ekA9GRfEpE1yQGDRvT9PConw73kKuupG') - 2016-12-20 02:51:11,756 INFO [sqlalchemy.engine.base.Engine:1140][MainThread] INSERT INTO users (name, role, password_hash) VALUES (?, ?, ?) - 2016-12-20 02:51:11,756 INFO [sqlalchemy.engine.base.Engine:1143][MainThread] ('basic', 'basic', '$2b$12$KgruXP5Vv7rikr6dGB3TF.flGXYpiE0Li9K583EVomjY.SYmQOsyi') - 2016-12-20 02:51:11,757 INFO [sqlalchemy.engine.base.Engine:1140][MainThread] INSERT INTO pages (name, data, creator_id) VALUES (?, ?, ?) - 2016-12-20 02:51:11,757 INFO [sqlalchemy.engine.base.Engine:1143][MainThread] ('FrontPage', 'This is the front page', 1) - 2016-12-20 02:51:11,757 INFO [sqlalchemy.engine.base.Engine:719][MainThread] COMMIT + Output goes here, once I figure out how to get the script to run. View the application in a browser -- cgit v1.2.3 From 3b6264fb0d5b88f07a91088df577ffc2a6c7bc9d Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Fri, 29 Jun 2018 01:34:45 -0700 Subject: Gardening of definingmodels.rst - Synch up emphasize-lines to new script changes - Update output examples --- docs/tutorials/wiki2/definingmodels.rst | 149 +++++++++++++++++--------------- 1 file changed, 80 insertions(+), 69 deletions(-) (limited to 'docs/tutorials/wiki2/definingmodels.rst') diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index 6fb4c0c1b..c22fd2b61 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -185,86 +185,86 @@ Success executing these commands will generate output similar to the following. .. code-block:: text - 2018-06-28 00:43:15,609 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 - 2018-06-28 00:43:15,609 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () - 2018-06-28 00:43:15,610 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 - 2018-06-28 00:43:15,610 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () - 2018-06-28 00:43:15,612 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA table_info("alembic_version") - 2018-06-28 00:43:15,612 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,613 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT alembic_version.version_num + 2018-06-29 01:28:42,407 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 + 2018-06-29 01:28:42,407 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-29 01:28:42,408 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 + 2018-06-29 01:28:42,408 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-29 01:28:42,409 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA table_info("alembic_version") + 2018-06-29 01:28:42,409 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,410 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT alembic_version.version_num FROM alembic_version - 2018-06-28 00:43:15,613 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,620 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT name FROM sqlite_master WHERE type='table' ORDER BY name - 2018-06-28 00:43:15,620 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,622 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA table_info("models") - 2018-06-28 00:43:15,622 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,623 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = 'models' AND type = 'table' - 2018-06-28 00:43:15,623 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,624 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA foreign_key_list("models") - 2018-06-28 00:43:15,624 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,624 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = 'models' AND type = 'table' - 2018-06-28 00:43:15,624 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,625 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_list("models") - 2018-06-28 00:43:15,625 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,625 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_info("my_index") - 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_list("models") - 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_info("my_index") - 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:43:15,626 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = 'models' AND type = 'table' - 2018-06-28 00:43:15,627 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - Generating //tutorial/tutorial/alembic/versions/20180628_9451789ab7d6.py ... done + 2018-06-29 01:28:42,410 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,411 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT name FROM sqlite_master WHERE type='table' ORDER BY name + 2018-06-29 01:28:42,412 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,413 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA table_info("models") + 2018-06-29 01:28:42,413 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,414 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = 'models' AND type = 'table' + 2018-06-29 01:28:42,414 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,414 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA foreign_key_list("models") + 2018-06-29 01:28:42,414 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,414 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = 'models' AND type = 'table' + 2018-06-29 01:28:42,415 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,416 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_list("models") + 2018-06-29 01:28:42,416 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,416 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_info("my_index") + 2018-06-29 01:28:42,416 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,417 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_list("models") + 2018-06-29 01:28:42,417 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,417 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA index_info("my_index") + 2018-06-29 01:28:42,417 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:28:42,417 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = 'models' AND type = 'table' + 2018-06-29 01:28:42,417 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + Generating //tutorial/tutorial/alembic/versions/20180629_23e9f8eb6c28.py ... done .. code-block:: text - 2018-06-28 00:46:18,152 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 - 2018-06-28 00:46:18,153 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () - 2018-06-28 00:46:18,153 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 - 2018-06-28 00:46:18,153 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () - 2018-06-28 00:46:18,155 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA table_info("alembic_version") - 2018-06-28 00:46:18,155 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:46:18,155 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT alembic_version.version_num + 2018-06-29 01:29:37,957 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 + 2018-06-29 01:29:37,958 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-29 01:29:37,958 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 + 2018-06-29 01:29:37,958 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-29 01:29:37,960 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] PRAGMA table_info("alembic_version") + 2018-06-29 01:29:37,960 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:29:37,960 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] SELECT alembic_version.version_num FROM alembic_version - 2018-06-28 00:46:18,155 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:46:18,159 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] + 2018-06-29 01:29:37,960 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:29:37,963 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] CREATE TABLE users ( - id INTEGER NOT NULL, - name TEXT NOT NULL, - role TEXT NOT NULL, - password_hash TEXT, - CONSTRAINT pk_users PRIMARY KEY (id), - CONSTRAINT uq_users_name UNIQUE (name) + id INTEGER NOT NULL, + name TEXT NOT NULL, + role TEXT NOT NULL, + password_hash TEXT, + CONSTRAINT pk_users PRIMARY KEY (id), + CONSTRAINT uq_users_name UNIQUE (name) ) - 2018-06-28 00:46:18,159 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:46:18,160 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT - 2018-06-28 00:46:18,161 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] + 2018-06-29 01:29:37,963 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:29:37,966 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + 2018-06-29 01:29:37,968 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] CREATE TABLE pages ( - id INTEGER NOT NULL, - name TEXT NOT NULL, - data TEXT NOT NULL, - creator_id INTEGER NOT NULL, - CONSTRAINT pk_pages PRIMARY KEY (id), - CONSTRAINT fk_pages_creator_id_users FOREIGN KEY(creator_id) REFERENCES users (id), - CONSTRAINT uq_pages_name UNIQUE (name) + id INTEGER NOT NULL, + name TEXT NOT NULL, + data TEXT NOT NULL, + creator_id INTEGER NOT NULL, + CONSTRAINT pk_pages PRIMARY KEY (id), + CONSTRAINT fk_pages_creator_id_users FOREIGN KEY(creator_id) REFERENCES users (id), + CONSTRAINT uq_pages_name UNIQUE (name) ) - 2018-06-28 00:46:18,161 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:46:18,162 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT - 2018-06-28 00:46:18,163 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] + 2018-06-29 01:29:37,968 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:29:37,969 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + 2018-06-29 01:29:37,969 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] DROP INDEX my_index - 2018-06-28 00:46:18,163 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:46:18,164 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT - 2018-06-28 00:46:18,164 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] + 2018-06-29 01:29:37,969 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:29:37,970 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + 2018-06-29 01:29:37,970 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] DROP TABLE models - 2018-06-28 00:46:18,164 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:46:18,165 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT - 2018-06-28 00:46:18,166 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] UPDATE alembic_version SET version_num='9451789ab7d6' WHERE alembic_version.version_num = 'd2f465a83563' - 2018-06-28 00:46:18,166 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () - 2018-06-28 00:46:18,166 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + 2018-06-29 01:29:37,970 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:29:37,971 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT + 2018-06-29 01:29:37,972 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] UPDATE alembic_version SET version_num='23e9f8eb6c28' WHERE alembic_version.version_num = 'b6b22ae3e628' + 2018-06-29 01:29:37,972 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] () + 2018-06-29 01:29:37,972 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT .. _wiki2_alembic_overview: @@ -310,7 +310,7 @@ following: .. literalinclude:: src/models/tutorial/scripts/initialize_db.py :linenos: :language: python - :emphasize-lines: 18,44-57 + :emphasize-lines: 11-24 Only the highlighted lines need to be changed. @@ -326,7 +326,18 @@ Success will look something like this: .. code-block:: text - Output goes here, once I figure out how to get the script to run. + 2018-06-29 01:30:39,326 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 + 2018-06-29 01:30:39,326 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-29 01:30:39,327 INFO [sqlalchemy.engine.base.Engine:1254][MainThread] SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 + 2018-06-29 01:30:39,327 INFO [sqlalchemy.engine.base.Engine:1255][MainThread] () + 2018-06-29 01:30:39,328 INFO [sqlalchemy.engine.base.Engine:682][MainThread] BEGIN (implicit) + 2018-06-29 01:30:39,329 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] INSERT INTO users (name, role, password_hash) VALUES (?, ?, ?) + 2018-06-29 01:30:39,329 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] ('editor', 'editor', '$2b$12$PlaJSN7goVbyx8OFs8yAju9n5gHGdI6PZ2QRJGM2jDCiEU4ItUNxy') + 2018-06-29 01:30:39,330 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] INSERT INTO users (name, role, password_hash) VALUES (?, ?, ?) + 2018-06-29 01:30:39,330 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] ('basic', 'basic', '$2b$12$MvXdM8jlkbjEyPZ6uXzRg.yatZZK8jCwfPaM7kFkmVJiJjRoCCvmW') + 2018-06-29 01:30:39,331 INFO [sqlalchemy.engine.base.Engine:1151][MainThread] INSERT INTO pages (name, data, creator_id) VALUES (?, ?, ?) + 2018-06-29 01:30:39,331 INFO [sqlalchemy.engine.base.Engine:1154][MainThread] ('FrontPage', 'This is the front page', 1) + 2018-06-29 01:30:39,332 INFO [sqlalchemy.engine.base.Engine:722][MainThread] COMMIT View the application in a browser @@ -335,11 +346,11 @@ View the application in a browser We can't. At this point, our system is in a "non-runnable" state; we'll need to change view-related files in the next chapter to be able to start the application successfully. If you try to start the application (see -:ref:`wiki2-start-the-application`), you'll wind up with a Python traceback on +:ref:`wiki2-start-the-application`) and visit http://localhost:6543, you'll wind up with a Python traceback on your console that ends with this exception: .. code-block:: text - ImportError: cannot import name MyModel + AttributeError: module 'tutorial.models' has no attribute 'MyModel' This will also happen if you attempt to run the tests. -- cgit v1.2.3