CREATE TABLE IF NOT EXISTS thread( id INTEGER PRIMARY KEY, title TEXT NOT NULL, time TIMESTAMP WITH TIME ZONE NOT NULL ); CREATE TABLE IF NOT EXISTS post( thread_id INTEGER REFERENCES thread(id) ON DELETE CASCADE NOT NULL, id INTEGER PRIMARY KEY, name TEXT NOT NULL, trip_code TEXT, subject TEXT, time TIMESTAMP WITH TIME ZONE NOT NULL, file_url TEXT, file_name TEXT, file_md5 TEXT, body TEXT NOT NULL ); CREATE TABLE IF NOT EXISTS link( link_from INTEGER REFERENCES post(id) ON DELETE CASCADE NOT NULL, link_to INTEGER REFERENCES post(id) ON DELETE CASCADE NOT NULL ); CREATE TABLE IF NOT EXISTS tag( post_id INTEGER REFERENCES post(id) ON DELETE CASCADE NOT NULL, name TEXT NOT NULL );