import os

from playhouse.migrate import *

cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern'))
db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db'))
migrator = SqliteMigrator(db)

date_added = DateTimeField(default=None)

migrate(
    migrator.add_column('torrent', 'date_added', date_added)
)

import datetime
import os

from playhouse.migrate import *

def update():
    cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern'))
    db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db'))
    migrator = SqliteMigrator(db)

    date_added = DateTimeField(default=datetime.datetime.now)

    migrate(
        migrator.add_column('torrent', 'date_added', date_added)
    )

Move migration to a function
Move migration to a function

+ import datetime
  import os
  
  from playhouse.migrate import *
  
+ def update():
- cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern'))
+     cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern'))
- db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db'))
+     db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db'))
- migrator = SqliteMigrator(db)
+     migrator = SqliteMigrator(db)
  
- date_added = DateTimeField(default=None)
+     date_added = DateTimeField(default=datetime.datetime.now)
  
- migrate(
+     migrate(
-     migrator.add_column('torrent', 'date_added', date_added)
+         migrator.add_column('torrent', 'date_added', date_added)
- )
+     )
  
Move migration to a function
## Code Before:
import os

from playhouse.migrate import *

cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern'))
db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db'))
migrator = SqliteMigrator(db)

date_added = DateTimeField(default=None)

migrate(
    migrator.add_column('torrent', 'date_added', date_added)
)

## Instruction:
Move migration to a function
## Code After:
import datetime
import os

from playhouse.migrate import *

def update():
    cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern'))
    db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db'))
    migrator = SqliteMigrator(db)

    date_added = DateTimeField(default=datetime.datetime.now)

    migrate(
        migrator.add_column('torrent', 'date_added', date_added)
    )
