# Copyricht (c) 2012 Michael Babich
# See LICENSE.txt or http://opensource.org/licenses/MIT

'''Defines the tables used by the database.
'''

from sqlalchemy import Table, Integer, ForeignKey, DateTime, Column, String, Boolean

def get_tables(metadata):
    table = {}

    def add_table(name, *columns):
        table[name] = Table(name, metadata,
                            Column('id', Integer, primary_key=True),
                            *columns)

    # TODO: posts, threads, users, urls, navbar, tags, styles
    # TODO: Work a per-forum karma system.

    # TODO: Work on a post revision system and a way to handle first
    # tags specially as content type.

    # TODO: Store parent/children/tags
    add_table('posts',
              Column('author', ForeignKey('users.username')),
              Column('karma', Integer),
              Column('content', String),
              Column('date', DateTime),
              Column('parent', ForeignKey('posts.id')))

    # TODO: Store tags/threaded/author... read it from 'start' post.
    add_table('thread',
              Column('start', ForeignKey('posts.id')),
              Column('title', String))

    add_table('users',
              Column('username', String, unique=True),
              Column('joined', DateTime),
              Column('email', String))

    add_table('nav',
              Column('visible', Boolean),
              Column('title', String),
              Column('text', String),
              Column('link', String))

    add_table('tags',
              Column('text', String),
              Column('color', String))

    add_table('forums',
              Column('name', String),
              Column('url', String))

    return table

@@ -271,19 +271,22 @@
     def 
-add
+create
 _table(n
@@ -706,27 +706,30 @@
 en/tags%0A    
-add
+create
 _table('post
@@ -728,24 +728,27 @@
 le('posts',%0A
+   
             
@@ -803,32 +803,35 @@
 ,%0A              
+  
+ 
 Column('karma', 
@@ -840,16 +840,19 @@
 teger),%0A
+   
         
@@ -890,32 +890,35 @@
 ,%0A              
+ 
+  
 Column('date', D
@@ -919,32 +919,35 @@
 te', DateTime),%0A
+   
               Co
@@ -1056,27 +1056,30 @@
 ' post.%0A    
-add
+create
 _table('thre
@@ -1083,16 +1083,19 @@
 hread',%0A
+   
         
@@ -1147,32 +1147,35 @@
 ,%0A              
+   
 Column('title', 
@@ -1180,35 +1180,38 @@
 , String))%0A%0A    
-add
+create
 _table('users',%0A
@@ -1206,24 +1206,27 @@
 le('users',%0A
+   
             
@@ -1260,32 +1260,35 @@
 , unique=True),%0A
+   
               Co
@@ -1319,32 +1319,35 @@
 ,%0A              
+   
 Column('email', 
@@ -1352,35 +1352,38 @@
 , String))%0A%0A    
-add
+create
 _table('nav',%0A  
@@ -1386,32 +1386,35 @@
 ,%0A              
+  
+ 
 Column('visible'
@@ -1431,32 +1431,35 @@
 ,%0A              
+   
 Column('title', 
@@ -1473,32 +1473,35 @@
 ,%0A              
+  
+ 
 Column('text', S
@@ -1500,32 +1500,35 @@
 text', String),%0A
+   
               Co
@@ -1546,35 +1546,38 @@
 , String))%0A%0A    
-add
+create
 _table('tags',%0A 
@@ -1581,32 +1581,35 @@
 ,%0A              
+ 
+  
 Column('text', S
@@ -1608,32 +1608,35 @@
 text', String),%0A
+   
               Co
@@ -1667,11 +1667,14 @@
     
-add
+create
 _tab
@@ -1682,24 +1682,27 @@
 e('forums',%0A
+   
             
@@ -1719,32 +1719,35 @@
 name', String),%0A
+   
               Co

Use 'create_table' as the function name because it matches the SQL function.