Permalink
Browse files

Working migration script.

  • Loading branch information...
1 parent af496e2 commit a6c432ed01a1230cb03fe9a73b5f1f2a21edf65d @svetlyak40wt committed Mar 16, 2009
View
@@ -1,2 +1,5 @@
check:
PYTHONPATH=`pwd` tests/testsuite.py
+
+dump:
+ echo '.schema' | sqlite3 todo.sqlite
View
@@ -7,11 +7,11 @@
from pdb import set_trace
class Task(Entity):
- title = Field(Unicode(40))
+ title = Field(Unicode(40), required = True)
note = Field(UnicodeText)
tags = ManyToMany('Tag')
- priority = Field(Float)
- done = Field(Boolean, default = False)
+ priority = Field(Float, default = 1, required = True)
+ done = Field(Boolean, default = False, required = True)
using_options(tablename='tasks', order_by='-priority')
@@ -26,7 +26,7 @@ def setTags(self, tags):
self.tags = [get_or_create(Tag, title = tag) for tag in tags]
class Tag(Entity):
- title = Field(Unicode(40), unique = True)
+ title = Field(Unicode(40), required = True, unique = True)
tasks = ManyToMany('Task')
using_options(tablename='tags', order_by='title')
@@ -0,0 +1,22 @@
+CREATE TABLE tags_new (
+ id INTEGER NOT NULL,
+ title VARCHAR(40) NOT NULL,
+ PRIMARY KEY (id),
+ UNIQUE (title)
+);
+CREATE TABLE tasks_new (
+ id INTEGER NOT NULL,
+ title VARCHAR(40) NOT NULL,
+ note TEXT,
+ priority FLOAT NOT NULL,
+ done BOOLEAN NOT NULL,
+ PRIMARY KEY (id)
+);
+
+INSERT INTO tags_new SELECT * FROM tags;
+INSERT INTO tasks_new SELECT * FROM tasks;
+
+DROP TABLE tags;
+ALTER TABLE tags_new RENAME TO tags;
+DROP TABLE tasks;
+ALTER TABLE tasks_new RENAME TO tasks;

0 comments on commit a6c432e

Please sign in to comment.