Skip to content

Commit

Permalink
Change from print to stdout.write (#5)
Browse files Browse the repository at this point in the history
* Change from `print()` to `self.stdout.write()`

* Don't need the default.

* Shortened line

* Version bump to 0.1.1

* Added CHANGELOG file.
  • Loading branch information
kennethlove authored Sep 26, 2024
1 parent 040e0eb commit 5fb2a57
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0.1.1 - Released 2024-09-26
* Minor format changes
* Removed an unnecessary default value
* Changed `print()` to `self.stdout.write()` in the migration commands

0.1.0 - Initial public release
* Updated the name of the project to "drifter"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description = "More migration commands to make development life simpler"
license = { file = "LICENSE.txt" }
name = "django-drifter"
requires-python = ">=3.10"
version = "0.1.0"
version = "0.1.1"

[project.optional-dependencies]
development = [
Expand Down
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
4 changes: 2 additions & 2 deletions src/drifter/management/commands/redo_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def handle(self, *args: object, **options: object) -> None:
cursor.execute("PRAGMA foreign_keys = OFF")

query = "SELECT * FROM django_migrations"
app_name = options.get("app", None)
app_name = options.get("app")
if app_name:
query += " WHERE app=%s "
query += " ORDER BY id DESC LIMIT 1"

cursor.execute(query, [app_name])
last_migration = cursor.fetchone()
if last_migration is None:
print("No migrations to redo")
self.stdout.write(self.style.WARNING("No migrations to redo"))
return

app_name = last_migration[1]
Expand Down
7 changes: 5 additions & 2 deletions src/drifter/management/commands/revert_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ def handle(self, *args: object, **options: object) -> None:
if migration_name.startswith("0001"):
migration_name = "zero" # Reset to initial state
else: # get previous migration name
query = "SELECT * FROM django_migrations WHERE app=%s AND id < %s ORDER BY id DESC LIMIT 1"
query = ("SELECT * FROM django_migrations WHERE app=%s "
"AND id < %s ORDER BY id DESC LIMIT 1")
cursor.execute(query, [app_name, migration[0]])
previous_migration = cursor.fetchone()
if previous_migration is not None:
migration_name = previous_migration[2]

try:
print(f"Reverting {app_name} to {migration_name}")
self.stdout.write(self.style.SUCCESS(
f"Reverting {app_name} to {migration_name}"
))
call_command("migrate", app_name, migration_name)
except CommandError as err:
error = "Error reverting migration"
Expand Down

0 comments on commit 5fb2a57

Please sign in to comment.