Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #27858 -- Prevented read-only commands from creating the django_migrations table. #8082

Merged
merged 1 commit into from Jun 19, 2017

Conversation

intgr
Copy link
Contributor

@intgr intgr commented Feb 18, 2017

MigrationRecorder is changed so that for read-only operations, if the
django_migrations table doesn't exist, it's assumed that no migrations
have been applied, instead of trying to create it.

Reverted documentation change from refs #23808.

@intgr intgr force-pushed the migration-readonly branch 8 times, most recently from baa8789 to ec21bac Compare February 21, 2017 00:04
@@ -1340,15 +1338,9 @@ def test_no_database(self):

def test_readonly_database(self):
"""
Ensure runserver.check_migrations doesn't choke when a database is read-only
(with possibly no django_migrations table).
Ensure runserver.check_migrations doesn't choke when a database is read-only.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still simluating a read-only database if the mocking is removed? Chop "Ensure" per https://code.djangoproject.com/ticket/27392.

@@ -163,7 +163,9 @@ Management Commands
Migrations
~~~~~~~~~~

* ...
* Commands that access migrations in a read-only manner, including
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a noteworthy feature that merits a mention in the release notes.

@@ -39,13 +39,19 @@ def __init__(self, connection):
def migration_qs(self):
return self.Migration.objects.using(self.connection.alias)

def has_table(self):
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Return True if the django_migrations table exists."""

@@ -86,6 +86,11 @@ def migrate(self, targets, plan=None, state=None, fake=False, fake_initial=False
Django first needs to create all project states before a migration is
(un)applied and in a second step run all the database operations.
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chop blank line

@@ -86,6 +86,11 @@ def migrate(self, targets, plan=None, state=None, fake=False, fake_initial=False
Django first needs to create all project states before a migration is
(un)applied and in a second step run all the database operations.
"""

# Make sure the migrations table is there. We don't want to fail with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested wording :# The django_migrations table must be present to record applied migrations.

self.ensure_schema()
return set(tuple(x) for x in self.migration_qs.values_list("app", "name"))
if self.has_table():
return set(tuple(x) for x in self.migration_qs.values_list("app", "name"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While here, might as well switch this to use single quotes per our coding style.

@@ -1340,15 +1338,9 @@ def test_no_database(self):

def test_readonly_database(self):
"""
Ensure runserver.check_migrations doesn't choke when a database is read-only
(with possibly no django_migrations table).
Ensure runserver.check_migrations doesn't choke when a database is read-only.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.cmd.check_migrations()
# Check a warning is emitted
self.assertIn("Not checking migrations", self.output.getvalue())
self.cmd.check_migrations()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still simulating a read-only database if the mocking is removed? This test might be obsolete considering the exception catching in check_migrations() is removed. Some low level tests for the modified MigrationRecorder methods might be in order instead.

MigrationRecorder, 'ensure_schema',
autospec=True, side_effect=patched_ensure_schema) as ensure_schema:
with mock.patch.object(MigrationRecorder, 'has_table', autospec=True,
side_effect=patched_has_table) as has_table:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the old indentation style was fine -- it allows for longer lines.

@timgraham timgraham changed the title Refs #27858 -- Changed makemigrations to not create migrations table Fixed #27858 -- Prevented read-only commands from creating the django_migrations table. Mar 7, 2017
… the django_migrations table.

MigrationRecorder now assumes that if the django_migrations table
doesn't exist, then no migrations are applied.

Reverted documentation change from refs #23808.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants