From 6b621f5ec71bc47e150b223dda74280060e5a8d7 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Tue, 16 Aug 2011 13:58:03 +0200 Subject: [PATCH] Add migration script for surveys In passing, make answers up to 500 characters, because that's required to perform the migration of existing ones... --- pgweb/survey/models.py | 18 +++++++++--------- tools/migrate/1_crunch_in_sql.sql | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/pgweb/survey/models.py b/pgweb/survey/models.py index 265859fe..f4d3eb65 100644 --- a/pgweb/survey/models.py +++ b/pgweb/survey/models.py @@ -17,15 +17,15 @@ class SurveyAnswerValues(object): self.votespercent = votespercent class Survey(PgModel, models.Model): - question = models.CharField(max_length=100, null=False, blank=False) - opt1 = models.CharField(max_length=100, null=False, blank=False) - opt2 = models.CharField(max_length=100, null=False, blank=False) - opt3 = models.CharField(max_length=100, null=False, blank=True) - opt4 = models.CharField(max_length=100, null=False, blank=True) - opt5 = models.CharField(max_length=100, null=False, blank=True) - opt6 = models.CharField(max_length=100, null=False, blank=True) - opt7 = models.CharField(max_length=100, null=False, blank=True) - opt8 = models.CharField(max_length=100, null=False, blank=True) + question = models.CharField(max_length=500, null=False, blank=False) + opt1 = models.CharField(max_length=500, null=False, blank=False) + opt2 = models.CharField(max_length=500, null=False, blank=False) + opt3 = models.CharField(max_length=500, null=False, blank=True) + opt4 = models.CharField(max_length=500, null=False, blank=True) + opt5 = models.CharField(max_length=500, null=False, blank=True) + opt6 = models.CharField(max_length=500, null=False, blank=True) + opt7 = models.CharField(max_length=500, null=False, blank=True) + opt8 = models.CharField(max_length=500, null=False, blank=True) posted = models.DateTimeField(null=False, default=datetime.now) current = models.BooleanField(null=False, default=False) diff --git a/tools/migrate/1_crunch_in_sql.sql b/tools/migrate/1_crunch_in_sql.sql index ad6d28c2..e21b059a 100644 --- a/tools/migrate/1_crunch_in_sql.sql +++ b/tools/migrate/1_crunch_in_sql.sql @@ -152,4 +152,19 @@ products.url, description, COALESCE(price,'') , products.lastconfirmed FROM oldweb.products INNER JOIN oldweb.organisations oo ON publisher=oo.id -INNER JOIN oldweb.product_categories ON category=product_categories.id; \ No newline at end of file +INNER JOIN oldweb.product_categories ON category=product_categories.id; + + +-- Surveys +TRUNCATE TABLE survey_surveyanswer CASCADE; +TRUNCATE TABLE survey_survey CASCADE; + +INSERT INTO survey_survey (id, question, opt1, opt2, opt3, opt4, opt5, opt6, opt7, opt8, posted, current) +SELECT surveyid, question, coalesce(opt1,''), coalesce(opt2,''), coalesce(opt3,''), coalesce(opt4,''), coalesce(opt5,''), coalesce(opt6,''), coalesce(opt7,''), coalesce(opt8,''), modified, current +FROM oldweb.survey_questions INNER JOIN oldweb.surveys ON surveys.id=survey_questions.surveyid; + +INSERT INTO survey_surveyanswer (survey_id, tot1, tot2, tot3, tot4, tot5, tot6, tot7, tot8) +SELECT id, tot1, tot2, tot3, tot4, tot5, tot6, tot7, tot8 +FROM oldweb.surveys; + +SELECT setval('survey_survey_id_seq', max(id)) FROM survey_survey;