added permanent solution to dbschema install; add db check; remove temp schema file

This commit is contained in:
muppeth 2024-02-22 13:31:10 +01:00
parent 08db441e2d
commit 6bbb66fc95
Signed by: muppeth
GPG Key ID: 0EBC7B9848D04031
2 changed files with 1 additions and 63 deletions

View File

@ -1,62 +0,0 @@
import lacre
import configparser
import sqlalchemy
import lacre.config as conf
# Values for lacre_keys.status column:
# - ST_DEFAULT: initial state;
# - ST_IMPORTED: key has been successfully processed by cron job;
# - ST_TO_BE_DELETED: key can be deleted.
ST_DEFAULT, ST_IMPORTED, ST_TO_BE_DELETED = range(3)
# lacre_keys.confirmed is set to an empty string when a key is confirmed by the user.
CO_CONFIRMED = ''
_meta = sqlalchemy.MetaData()
LACRE_KEYS = sqlalchemy.Table('lacre_keys', _meta,
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True),
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('time', sqlalchemy.DateTime))
LACRE_IDENTITIES = sqlalchemy.Table('lacre_identities', _meta,
sqlalchemy.Column('email', sqlalchemy.String(256), index=True),
# Key fingerprint
sqlalchemy.Column('fingerprint', sqlalchemy.String(64), index=True))
LACRE_LOCKS = sqlalchemy.Table('lacre_locks', _meta,
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True),
sqlalchemy.Column('ip', sqlalchemy.String(16), index=True),
sqlalchemy.Column('time', sqlalchemy.Integer),
sqlalchemy.Column('action', sqlalchemy.String(16), index=True),
sqlalchemy.Column('num', sqlalchemy.Integer))
def _validate_config():
missing = conf.validate_config()
if missing:
params = ", ".join([_full_param_name(tup) for tup in missing])
LOG.error(f"Following mandatory parameters are missing: {params}")
sys.exit(lacre.EX_CONFIG)
def init_identities_table() -> sqlalchemy.Table:
return LACRE_IDENTITIES
def create_tables(engine):
_meta.create_all(engine)
def table_metadata():
return _meta
if __name__ == "__main__":
conf.load_config()
connection_string = keyring_path = conf.get_item('database', 'url')
engine = sqlalchemy.create_engine(connection_string)
create_tables(engine)

View File

@ -83,7 +83,7 @@
- name: '[INSTALL] - Run dbschema'
shell:
cmd: '{{ lacre_homedir }}/venv/bin/python{{ lacre_python_version }} -m {{ lacre_app_dir }}/lacre/lacre.admin db -i'
cmd: '{{ lacre_homedir }}/venv/bin/python{{ lacre_python_version }} -m {{ lacre_app_dir }}/lacre/admin.py db -i'
become: 'yes'
become_user: '{{ lacre_username }}'
when: lacre_db_info.stdout != '3'