gtaylor convinced me to add migrations to the Evennia repo. This means that game/migrate.py is no more. The migrations will help you to adjust your database when Evennia releases a new database change, no need to drop the database or manually adjust tables. To make use of our schema migrations, you need to have Django-South installed.
To convert to django-south operations, easiest is if you are willing to drop your old database (e.g. delete evennia.db if you use default sqlite3). Then do: "game/manage.py syncdb" followed by "game/manage.py migrate". That should do it. If you ever deletes your database, just rerun those two commands. If you want to convert an existing database, do game/manage.py convert_to_south comms game/manage.py convert_to_south config game/manage.py convert_to_south help game/manage.py convert_to_south objects game/manage.py convert_to_south players game/manage.py convert_to_south scripts In the future, you will then be able to do ./manage.py migrate when we tell you the schema has changed.
This commit is contained in:
parent
75956de7d1
commit
9b9f90d91c
13 changed files with 670 additions and 145 deletions
145
game/migrate.py
145
game/migrate.py
|
|
@ -1,145 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
|
||||
Database migration helper, using South.
|
||||
|
||||
Usage:
|
||||
|
||||
- Install South using the method suitable for your platform
|
||||
http://south.aeracode.org/docs/installation.html
|
||||
|
||||
- You need to have a database setup, either an old one or
|
||||
a fresh one. If the latter, run manage.py syncdb as normal,
|
||||
entering superuser info etc.
|
||||
|
||||
- Start this tool and use the 'initialize' option. South will
|
||||
create a migration scheme for all Evennia components.
|
||||
|
||||
That's all you need to do until Evennia's database scheme changes,
|
||||
something which is usually announced with the update. To update
|
||||
your current database automatically, follow these steps:
|
||||
|
||||
- Run this tool
|
||||
|
||||
- Select the Update option.
|
||||
|
||||
That is all. :)
|
||||
|
||||
For more advanced migrations, there might be further instructions.
|
||||
|
||||
"""
|
||||
|
||||
import os, sys
|
||||
from subprocess import call
|
||||
import south
|
||||
|
||||
# Set the Python path up so we can get to settings.py from here.
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings'
|
||||
|
||||
if not os.path.exists('settings.py'):
|
||||
# make sure we have a settings.py file.
|
||||
print " No settings.py file found. Launching manage.py ..."
|
||||
|
||||
import game.manage
|
||||
|
||||
print """
|
||||
Now configure Evennia by editing your new settings.py file.
|
||||
If you haven't already, you should also create/configure the
|
||||
database with 'python manage.py syncdb' before continuing."""
|
||||
sys.exit()
|
||||
|
||||
# Get the settings
|
||||
from django.conf import settings
|
||||
|
||||
# Prepare all valid apps
|
||||
APPLIST = [app.split('.')[-1] for app in settings.INSTALLED_APPS
|
||||
if app.startswith("src.") or app.startswith("game.")]
|
||||
|
||||
def run_south(mode):
|
||||
"""
|
||||
Simply call manage.py with the appropriate South commands.
|
||||
"""
|
||||
if mode == "init":
|
||||
for appname in APPLIST:
|
||||
print "Initializing %s ... (ignore missing directory tracebacks)" % appname
|
||||
call([sys.executable, "manage.py", "convert_to_south", appname])
|
||||
print "\nInitialization complete. That's all you need to do for now."
|
||||
elif mode == "update":
|
||||
for appname in APPLIST:
|
||||
print "Updating/migrating schema for %s ..." % appname
|
||||
call([sys.executable, "manage.py", "schemamigration", appname, "--auto"])
|
||||
call([sys.executable, "manage.py", "migrate", appname])
|
||||
print "\nUpdate complete."
|
||||
elif mode == "remove":
|
||||
s = raw_input(" Warning, this cannot be undone. Continue? Y[N] > ")
|
||||
if s.lower() == 'y':
|
||||
from django.db.models import get_app
|
||||
import shutil
|
||||
for appname in APPLIST:
|
||||
print "Removing migrations for %s ..." % appname
|
||||
mod = get_app(appname)
|
||||
path = os.path.join(os.path.dirname(mod.__file__), 'migrations')
|
||||
try:
|
||||
shutil.rmtree(path)
|
||||
except OSError:
|
||||
print "%s didn't exist/could not be deleted. Ignored.." % path
|
||||
|
||||
def south_ui():
|
||||
"""
|
||||
Simple menu for handling migrations.
|
||||
"""
|
||||
|
||||
string = """
|
||||
Evennia Database Migration Tool
|
||||
|
||||
You usually don't need to use this tool unless a new version of Evennia
|
||||
tells you that the database scheme changed in some way, AND you don't want
|
||||
to reset your database. If you
|
||||
|
||||
This tool will help you to migrate an existing database without having to
|
||||
manually edit your tables and fields to match the new scheme. For that
|
||||
to work you must have run this tool *before* applying the changes however.
|
||||
|
||||
This is a simple wrapper on top of South, a Django database scheme
|
||||
migration tool.
|
||||
|
||||
If you want more control, you can call manage.py directly using the
|
||||
instructions found at http://south.aeracode.org/docs.
|
||||
|
||||
NOTE: Evennia is still in Alpha - there is no guarantee that database
|
||||
changes will still not be too advanced to handle with this simple
|
||||
tool, and it is too soon to talk of supplying custom migration
|
||||
schemes to new versions.
|
||||
|
||||
Options:
|
||||
|
||||
i - Initialize an existing/new database with migration mappings (done once)
|
||||
u - Update an initialized database to the changed scheme
|
||||
r - Remove the migration scheme (back to normal syncdb operation)
|
||||
q - Quit
|
||||
"""
|
||||
|
||||
while True:
|
||||
print string
|
||||
inp = str(raw_input(" Option > "))
|
||||
inp = inp.lower()
|
||||
if inp in ["q", "i", "u", "r"]:
|
||||
if inp == 'i':
|
||||
run_south("init")
|
||||
elif inp == 'u':
|
||||
run_south("update")
|
||||
elif inp == 'r':
|
||||
run_south("remove")
|
||||
sys.exit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
if not 'south' in settings.INSTALLED_APPS:
|
||||
string = "\n The 'south' database migration tool does not seem to be installed."
|
||||
string += "\n You can find it here: http://south.aeracide.org.\n"
|
||||
print string
|
||||
else:
|
||||
south_ui()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue