Adjust lacre.dbschema to reflect original schema.sql
- Set nullability of columns. - Set up primary keys and auto-increment where necessary. - Add missing 'lacre_locks' table. - Implement a function to create tables.
This commit is contained in:
parent
be615df6e4
commit
f7e6708949
1 changed files with 23 additions and 4 deletions
|
@ -7,6 +7,8 @@ This definition includes:
|
|||
|
||||
- 'lacre_identities' -- identity catalogue, used by encryption logic to match
|
||||
emails with corresponding keys.
|
||||
|
||||
- 'lacre_locks' -- used only by the frontend.
|
||||
"""
|
||||
|
||||
import sqlalchemy
|
||||
|
@ -23,23 +25,40 @@ CO_CONFIRMED = ''
|
|||
_meta = sqlalchemy.MetaData()
|
||||
|
||||
LACRE_KEYS = sqlalchemy.Table('lacre_keys', _meta,
|
||||
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True),
|
||||
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True, autoincrement='auto'),
|
||||
sqlalchemy.Column('email', sqlalchemy.String(256), index=True),
|
||||
# ASCII-armored key
|
||||
sqlalchemy.Column('publickey', sqlalchemy.Text),
|
||||
# Empty string means this key has been confirmed.
|
||||
sqlalchemy.Column('confirm', sqlalchemy.String(32)),
|
||||
# Status: see ST_* constants at the top of the file.
|
||||
sqlalchemy.Column('status', sqlalchemy.Integer),
|
||||
sqlalchemy.Column('status', sqlalchemy.Integer, nullable=False),
|
||||
sqlalchemy.Column('time', sqlalchemy.DateTime))
|
||||
|
||||
LACRE_LOCKS = sqlalchemy.Table('lacre_locks', _meta,
|
||||
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True, nullable=False, autoincrement='auto'),
|
||||
sqlalchemy.Column('ip', sqlalchemy.String(16)),
|
||||
sqlalchemy.Column('time', sqlalchemy.Integer),
|
||||
sqlalchemy.Column('action', sqlalchemy.String(16)),
|
||||
sqlalchemy.Column('num', sqlalchemy.Integer),
|
||||
)
|
||||
|
||||
LACRE_IDENTITIES = sqlalchemy.Table('lacre_identities', _meta,
|
||||
sqlalchemy.Column('email', sqlalchemy.String(256), index=True),
|
||||
sqlalchemy.Column('email', sqlalchemy.String(256), index=True, nullable=False),
|
||||
# Key fingerprint
|
||||
sqlalchemy.Column('fingerprint', sqlalchemy.String(64), index=True))
|
||||
sqlalchemy.Column('fingerprint', sqlalchemy.String(64), index=True, nullable=False))
|
||||
|
||||
def init_identities_table() -> sqlalchemy.Table:
|
||||
return LACRE_IDENTITIES
|
||||
|
||||
def init_locks_table() -> sqlalchemy.Table:
|
||||
return LACRE_LOCKS
|
||||
|
||||
def init_keys_table() -> sqlalchemy.Table:
|
||||
return LACRE_KEYS
|
||||
|
||||
def create_tables(engine):
|
||||
_meta.create_all(engine)
|
||||
|
||||
def table_metadata():
|
||||
return _meta
|
||||
|
|
Loading…
Reference in a new issue