M dbcache/schema.py +1 -13
@@ 15,16 15,4 @@ def init(engine, ns='cache', drop=False)
)
with engine.begin() as cn:
- exists = cn.execute(
- 'select exists ('
- ' select from information_schema.tables '
- ' where table_schema = %(schema_name)s and'
- ' table_name = %(table_name)s'
- ')',
- schema_name=ns,
- table_name='things'
- ).scalar()
- if not exists:
- cn.execute(sqlfile(SQLFILE, ns=ns))
- else:
- print(f'dbcache: "{ns}"."things" already exists.')
+ cn.execute(sqlfile(SQLFILE, ns=ns))
M dbcache/schema.sql +6 -8
@@ 1,30 1,28 @@
-create schema "{ns}";
+create schema if not exists "{ns}";
-create table "{ns}".things (
+create table if not exists "{ns}".things (
id serial primary key,
idate timestamptz not null default now(),
validity interval not null default '10 minutes',
- key text not null,
+ key text unique not null,
value bytea not null
);
-create unique index on "{ns}".things(key);
-
-create table "{ns}".kvstore (
+create table if not exists "{ns}".kvstore (
id serial primary key,
key text unique not null,
value jsonb not null
);
-create table "{ns}".vkvstore (
+create table if not exists "{ns}".vkvstore (
id serial primary key,
key text unique not null
);
-create table "{ns}".version (
+create table if not exists "{ns}".version (
id serial primary key,
objid integer references "{ns}".vkvstore(id) on delete cascade,
idate timestamptz not null default now(),