def prepare_db(): pyrails.get_database(debug=False).execute_rowcount( """create table users ( id integer auto_increment primary key, name varchar(32), age integer, gender varchar(4) );""" ) pyrails.get_database(debug=False).execute_rowcount( """create table categories( id integer auto_increment primary key, name varchar(32) );""" ) pyrails.get_database(debug=False).execute_rowcount( """create table posts ( id integer auto_increment primary key, title varchar(128), content text, user_id integer, foreign key (user_id) references users(id) );""" ) pyrails.get_database(debug=False).execute_rowcount( """create table categories_posts ( id integer auto_increment primary key, category_id integer, post_id integer, foreign key (category_id) references categories(id), foreign key (post_id) references posts(id) );""" )
def drop_db(): pyrails.get_database(debug=False).execute_rowcount("drop table categories_posts") pyrails.get_database(debug=False).execute_rowcount("drop table posts") pyrails.get_database(debug=False).execute_rowcount("drop table categories") pyrails.get_database(debug=False).execute_rowcount("drop table users")