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

Migrations attempt to run Vim swap files #743

Open
bezborodow opened this issue Jan 31, 2023 · 3 comments
Open

Migrations attempt to run Vim swap files #743

bezborodow opened this issue Jan 31, 2023 · 3 comments
Labels

Comments

@bezborodow
Copy link

Describe the bug

Vim creates swapfiles when editing a file. They take the filename format .filename.swp.

If migrations are run with swapfiles present, the migrations attempt to execute them, causing an error:

(venv) ~/src/gaas-bms$ python craft migrate
Migrating: .2023_01_31_175104_create_accounts_table.swp

  TypeError

  'NoneType' object is not callable

  at venv/lib/python3.10/site-packages/masoniteorm/migrations/Migration.py:143 in migrate
      139│                 self.command_class.line(
      140│                     f"Migrating: {migration}"
      141│                 )
      142│ 
    → 143│             migration_class = migration_class(
      144│                 connection=self.connection, schema=self.schema_name
      145│             )
      146│ 
      147│             if output:

In the above example, python craft migrate attempts to run the migration file .2023_01_31_175104_create_accounts_table.swp, which the expected behaviour is that it should be ignored.

This could be fixed for Vim (and also any other text editor that does the same) by ignoring any migration file that begins with a dot (.) at the beginning of the filename. This is generally accepted convention to ignore such files in most cases.

Expected behaviour

Ignore all migration files that begin with a dot (..)

Steps to reproduce the bug

Create the migration:

python craft migration create_accounts_table --create accounts

Open the migration file in Vim.

Run the migration with Vim still open in the background:

python craft migrate
(venv) ~/src/gaas-bms$ pip show masonite | grep Version
Version: 4.17.4

Screenshots

No response

OS

Linux

OS version

Ubuntu 22.04.1 LTS (5.15.0-58-generic x86_64 GNU/Linux)

Browser

No response

Masonite Version

4.17.4

Anything else ?

No response

@bezborodow bezborodow added the bug label Jan 31, 2023
@bezborodow
Copy link
Author

bezborodow commented Jan 31, 2023

This is my fix:

diff -Naur Migration.py ~/src/gaas-bms/venv/lib/python3.10/site-packages/masoniteorm/migrations/Migration.py 
--- Migration.py        2023-01-31 18:19:56.486556917 +1030
+++ /home/damien/src/gaas-bms/venv/lib/python3.10/site-packages/masoniteorm/migrations/Migration.py     2023-01-31 18:17:42.996494337 +1030
@@ -60,7 +60,7 @@
         all_migrations = [
             f.replace(".py", "")
             for f in listdir(directory_path)
-            if isfile(join(directory_path, f)) and f != "__init__.py"
+            if isfile(join(directory_path, f)) and f != "__init__.py" and not f.startswith('.')
         ]
         all_migrations.sort()
         unran_migrations = []
@@ -107,7 +107,7 @@
         all_migrations = [
             f.replace(".py", "")
             for f in listdir(directory_path)
-            if isfile(join(directory_path, f)) and f != "__init__.py"
+            if isfile(join(directory_path, f)) and f != "__init__.py" and not f.startswith('.')
         ]
         all_migrations.sort()
         ran = []

However, it seems I should log this issue in the orm package. I'll create a pull request there.

@bezborodow
Copy link
Author

bezborodow commented Jan 31, 2023

I have created a pull request in the orm package: MasoniteFramework/orm#835, Migrations should ignore dotfiles.

@bezborodow
Copy link
Author

It might also be best to only run migration filenames that end in .py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant