This was a very simple ticket actually. I created a list called FOUNDATIONS in
authortilly-Q <nattilypigeonfowl@gmail.com>
Mon, 29 Jul 2013 20:36:06 +0000 (16:36 -0400)
committertilly-Q <nattilypigeonfowl@gmail.com>
Mon, 29 Jul 2013 20:36:06 +0000 (16:36 -0400)
mediagoblin/db/models.py. This list holds all of the information about rows that
should be created at database initialization. Read the documentation near the
FOUNDATIONS list to understand the proper format for this list.

All of the work is done through a new method on MigrationManager in
mediagoblin/db/migrations_tools.py. This method, `populate_table_foundations`
parses the FOUNDATIONS list and creates the foundations based on the data incl-
uded. This only ever happens when the database is initialized. Migrations to
releases with new Foundations should be very easy just using the basic
database functionality.

mediagoblin/db/migration_tools.py
mediagoblin/db/models.py

index aa22ef94525a79204bd7c5edc2951ca8d5899a95..1192836d8691642ed7222e94b031df96f47fd055 100644 (file)
@@ -140,6 +140,18 @@ class MigrationManager(object):
             self.session.bind,
             tables=[model.__table__ for model in self.models])
 
+    def populate_table_foundations(self):
+        """
+        Create the table foundations (default rows) as layed out in FOUNDATIONS
+            in mediagoblin.db.models
+        """
+        from mediagoblin.db.models import FOUNDATIONS as MAIN_FOUNDATIONS
+        for Model, rows in MAIN_FOUNDATIONS.items():
+            print u'\n--> Laying foundations for %s table' % Model.__name__
+            for parameters in rows:
+                row = Model(**parameters)
+                row.save()
+
     def create_new_migration_record(self):
         """
         Create a new migration record for this migration set
@@ -202,7 +214,9 @@ class MigrationManager(object):
 
             self.init_tables()
             # auto-set at latest migration number
-            self.create_new_migration_record()  
+            self.create_new_migration_record()
+            if self.name==u'__main__':
+                self.populate_table_foundations()
             
             self.printer(u"done.\n")
             self.set_current_migration()
index 826d47baa0a36b47aaf8699c23027d4b3afa9d4d..7448f5ce166c5e7b21b2141c79a98392e50b233e 100644 (file)
@@ -585,6 +585,21 @@ MODELS = [
     Notification, CommentNotification, ProcessingNotification,
     CommentSubscription]
 
+"""
+ Foundations are the default rows that are created immediately after the tables 
+ are initialized. Each entry to  this dictionary should be in the format of:
+                 ModelConstructorObject:List of Dictionaries
+ (Each Dictionary represents a row on the Table to be created, containing each
+  of the columns' names as a key string, and each of the columns' values as a
+  value)
+
+ ex. [NOTE THIS IS NOT BASED OFF OF OUR USER TABLE]
+    user_foundations = [{'name':u'Joanna', 'age':24},
+                        {'name':u'Andrea', 'age':41}]
+
+    FOUNDATIONS = {User:user_foundations}
+"""
+FOUNDATIONS = {}
 
 ######################################################
 # Special, migrations-tracking table