diff options
author | Parker <contact@pkrm.dev> | 2024-02-25 02:15:31 -0600 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-02-25 02:15:31 -0600 |
commit | 0ea4abca33363f0bbdffa181b60beefc247774fa (patch) | |
tree | 0a6dcd17d5a6d7d9fdb1395548fb33cedf559f2c /app/db.py | |
parent | f3ff78bc8db5d8e7938407a62d56410cc72ce3a7 (diff) |
Creation
Diffstat (limited to 'app/db.py')
-rw-r--r-- | app/db.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/db.py b/app/db.py new file mode 100644 index 0000000..4d41dcc --- /dev/null +++ b/app/db.py @@ -0,0 +1,31 @@ +import sqlalchemy + +engine = sqlalchemy.create_engine('sqlite:///data.db') + +def init_db(): + with engine.begin() as conn: + conn.execute(sqlalchemy.text( + ''' + CREATE TABLE IF NOT EXISTS accounts ( + account_name, PRIMARY KEY (account_name) + ) + ''' + )) + conn.execute(sqlalchemy.text( + ''' + CREATE TABLE IF NOT EXISTS links ( + owner, link, redirect_link, expire_date, + FOREIGN KEY (owner) REFERENCES accounts(account_name), PRIMARY KEY (link) + ) + ''' + )) + conn.execute(sqlalchemy.text( + ''' + CREATE TABLE IF NOT EXISTS records ( + owner, link, timestamp, ip, location, browser, os, user_agent, isp, + FOREIGN KEY (owner) REFERENCES links(owner), + FOREIGN KEY (link) REFERENCES links(link)) + ''' + )) + + conn.commit()
\ No newline at end of file |