Spaces:
Sleeping
Sleeping
import sqlite3 | |
def create_database(): | |
"""Creates a SQLite database with personas and posts tables.""" | |
conn = sqlite3.connect("personas.db") # This creates the database file | |
cursor = conn.cursor() | |
# Create the personas table | |
cursor.execute(''' | |
CREATE TABLE IF NOT EXISTS personas ( | |
persona_id INTEGER PRIMARY KEY AUTOINCREMENT, | |
name TEXT UNIQUE NOT NULL, | |
description TEXT | |
) | |
''') | |
# Create the posts table | |
cursor.execute(''' | |
CREATE TABLE IF NOT EXISTS posts ( | |
post_id INTEGER PRIMARY KEY AUTOINCREMENT, | |
persona_id INTEGER, | |
text_blocks TEXT NOT NULL, | |
tags TEXT, | |
FOREIGN KEY (persona_id) REFERENCES personas(persona_id) | |
) | |
''') | |
conn.commit() | |
conn.close() | |
print("Database and tables created successfully!") | |
# Run the function | |
create_database() | |