forked from 0x2620/pandora
fix inital database creation
This commit is contained in:
parent
ab9b5adc92
commit
5392750348
5 changed files with 58 additions and 12 deletions
2
README
2
README
|
@ -97,7 +97,9 @@ Important: "use_your_own" is a password and you have to use the same value here
|
|||
su pandora
|
||||
cd /srv/pandora/pandora
|
||||
./manage.py syncdb --noinput
|
||||
./manage.py migrate
|
||||
./manage.py sqlfindindex | ./manage.py dbshell
|
||||
./manage.py sync_itemsort
|
||||
./manage.py collectstatic -l --noinput
|
||||
./manage.py update_static
|
||||
./manage.py compile_pyc
|
||||
|
|
|
@ -6,6 +6,10 @@ from django.db import models
|
|||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
depends_on = (
|
||||
("item", "0001_initial"),
|
||||
("clip", "0001_initial"),
|
||||
)
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding model 'Annotation'
|
||||
|
@ -179,4 +183,4 @@ class Migration(SchemaMigration):
|
|||
}
|
||||
}
|
||||
|
||||
complete_apps = ['annotation']
|
||||
complete_apps = ['annotation']
|
||||
|
|
|
@ -51,15 +51,20 @@ def load_config():
|
|||
|
||||
settings.CONFIG = config
|
||||
admin = len(settings.CONFIG['userLevels']) - 1
|
||||
if not 'syncdb' in sys.argv and not 'sqldiff' in sys.argv:
|
||||
if User.objects.filter(profile__level=admin).count() == 0:
|
||||
for u in User.objects.filter(is_superuser=True):
|
||||
p = u.get_profile()
|
||||
p.level = admin
|
||||
p.save()
|
||||
settings.ADMIN = tuple([(u.username, u.email)
|
||||
for u in User.objects.filter(profile__level=admin)])
|
||||
settings.MANAGERS = settings.ADMINS
|
||||
if not 'syncdb' in sys.argv \
|
||||
and not 'sqldiff' in sys.argv \
|
||||
and not 'migrate' in sys.argv:
|
||||
try:
|
||||
if User.objects.filter(profile__level=admin).count() == 0:
|
||||
for u in User.objects.filter(is_superuser=True):
|
||||
p = u.get_profile()
|
||||
p.level = admin
|
||||
p.save()
|
||||
settings.ADMIN = tuple([(u.username, u.email)
|
||||
for u in User.objects.filter(profile__level=admin)])
|
||||
settings.MANAGERS = settings.ADMINS
|
||||
except:
|
||||
pass
|
||||
|
||||
def reloader_thread():
|
||||
_config_mtime = 0
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import connection, transaction
|
||||
from django.db.models import fields
|
||||
|
||||
import monkey_patch.models
|
||||
from ... import models
|
||||
|
||||
import clip.models
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
|
@ -14,6 +16,10 @@ class Command(BaseCommand):
|
|||
"""
|
||||
help = 'alter table to match itemKeys in site.json.'
|
||||
args = ''
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--debug', action='store_true', dest='debug',
|
||||
default=False, help='print sql commans'),
|
||||
)
|
||||
|
||||
def handle(self, **options):
|
||||
table_name = models.ItemSort._meta.db_table
|
||||
|
@ -56,10 +62,35 @@ class Command(BaseCommand):
|
|||
sql = 'ALTER TABLE "%s" ALTER COLUMN "%s" %s NOT NULL' % (table_name, name,
|
||||
f.null and "DROP" or "SET")
|
||||
changes.append(sql)
|
||||
|
||||
#also update clip index
|
||||
table_name = clip.models.Clip._meta.db_table
|
||||
db_rows = connection.introspection.get_table_description(cursor, table_name)
|
||||
db_fields = dict([(row[0], row) for row in db_rows])
|
||||
db_types = dict([(row[0],
|
||||
connection.introspection.data_types_reverse[row[1]]) for row in db_rows])
|
||||
model_fields = ['item_id', 'sort_id'] + [f.name for f in clip.models.Clip._meta.fields]
|
||||
|
||||
for name in db_types:
|
||||
if name not in model_fields:
|
||||
sql = 'ALTER TABLE "%s" DROP COLUMN "%s"' % (table_name, name)
|
||||
changes.append(sql)
|
||||
for f in clip.models.Clip._meta.fields:
|
||||
if not f.primary_key and not isinstance(f, fields.related.ForeignKey):
|
||||
name = f.name
|
||||
col_type = f.db_type(connection)
|
||||
if name not in db_fields:
|
||||
sql = 'ALTER TABLE "%s" ADD COLUMN "%s" %s' % (table_name, name, col_type)
|
||||
changes.append(sql)
|
||||
sql = 'CREATE INDEX "%s_%s_idx" ON "%s" ("%s")' % (table_name, name,
|
||||
table_name, name)
|
||||
changes.append(sql)
|
||||
sql = 'ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (table_name, name)
|
||||
changes.append(sql)
|
||||
if changes:
|
||||
print "Database needs to be updated, plase wait..."
|
||||
for sql in changes:
|
||||
print sql
|
||||
if options['debug']:
|
||||
print sql
|
||||
cursor.execute(sql)
|
||||
transaction.commit_unless_managed()
|
||||
|
|
|
@ -42,6 +42,10 @@ class Migration(SchemaMigration):
|
|||
))
|
||||
db.create_unique('item_item_groups', ['item_id', 'group_id'])
|
||||
|
||||
# Adding model 'ItemSort'
|
||||
db.create_table('item_itemsort', (
|
||||
('item', self.gf('django.db.models.fields.related.ForeignKey')(related_name='sort', to=orm['item.Item'],primary_key=True)),
|
||||
))
|
||||
# Adding model 'ItemFind'
|
||||
db.create_table('item_itemfind', (
|
||||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||
|
|
Loading…
Reference in a new issue