2019-12-13 13:55:30 +01:00
|
|
|
import asyncpg
|
|
|
|
import asyncio
|
|
|
|
from risotto.config import get_config
|
|
|
|
|
|
|
|
VERSION_INIT = """
|
|
|
|
-- Création de la table Source
|
|
|
|
CREATE TABLE Source (
|
|
|
|
SourceId SERIAL PRIMARY KEY,
|
|
|
|
SourceName VARCHAR(255) NOT NULL UNIQUE,
|
|
|
|
SourceURL TEXT
|
|
|
|
);
|
|
|
|
|
|
|
|
-- Création de la table Release
|
|
|
|
CREATE TABLE Release (
|
|
|
|
ReleaseId SERIAL PRIMARY KEY,
|
|
|
|
ReleaseName VARCHAR(255) NOT NULL,
|
|
|
|
ReleaseSourceId INTEGER NOT NULL,
|
|
|
|
UNIQUE (ReleaseName, ReleaseSourceId),
|
|
|
|
FOREIGN KEY (ReleaseSourceId) REFERENCES Source(SourceId)
|
|
|
|
);
|
|
|
|
|
2019-12-13 16:42:10 +01:00
|
|
|
-- Création de la table Servermodel
|
|
|
|
CREATE TABLE Servermodel (
|
|
|
|
ServermodelId SERIAL PRIMARY KEY,
|
|
|
|
ServermodelName VARCHAR(255) NOT NULL,
|
|
|
|
ServermodelDescription VARCHAR(255) NOT NULL,
|
|
|
|
ServermodelParentsId INTEGER [] DEFAULT '{}',
|
|
|
|
ServermodelReleaseId INTEGER NOT NULL,
|
|
|
|
ServermodelApplicationServiceId INTEGER NOT NULL,
|
|
|
|
ServermodelUsers hstore,
|
|
|
|
UNIQUE (ServermodelName, ServermodelReleaseId)
|
2019-12-13 13:55:30 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
-- Création de la table ApplicationService
|
|
|
|
CREATE TABLE ApplicationService (
|
|
|
|
ApplicationServiceId SERIAL PRIMARY KEY,
|
|
|
|
ApplicationServiceName VARCHAR(255) NOT NULL,
|
|
|
|
ApplicationServiceDescription VARCHAR(255) NOT NULL,
|
|
|
|
ApplicationServiceReleaseId INTEGER NOT NULL,
|
|
|
|
ApplicationServiceDependencies JSON,
|
|
|
|
UNIQUE (ApplicationServiceName, ApplicationServiceReleaseId)
|
|
|
|
);
|
|
|
|
|
|
|
|
-- Création de la table de jointure ApplicationServiceProvides
|
|
|
|
CREATE TABLE ApplicationServiceProvides (
|
|
|
|
ApplicationServiceId INTEGER NOT NULL,
|
|
|
|
VirtualApplicationServiceId INTEGER NOT NULL,
|
|
|
|
FOREIGN KEY (ApplicationServiceId) REFERENCES ApplicationService(ApplicationServiceId),
|
|
|
|
FOREIGN KEY (VirtualApplicationServiceId) REFERENCES ApplicationService(ApplicationServiceId),
|
|
|
|
PRIMARY KEY (ApplicationServiceId, VirtualApplicationServiceId)
|
|
|
|
);
|
|
|
|
|
|
|
|
-- Création de la table Package
|
|
|
|
CREATE TABLE Package (
|
|
|
|
PackageId SERIAL PRIMARY KEY,
|
|
|
|
PackageApplicationServiceId INTEGER,
|
|
|
|
PackageName VARCHAR(255) NOT NULL,
|
|
|
|
FOREIGN KEY (PackageApplicationServiceId) REFERENCES ApplicationService(ApplicationServiceId)
|
|
|
|
);
|
|
|
|
|
|
|
|
-- Création de la table Document
|
|
|
|
CREATE TABLE Document (
|
|
|
|
DocumentId SERIAL PRIMARY KEY,
|
|
|
|
DocumentServiceId INTEGER,
|
|
|
|
DocumentName VARCHAR(255) NOT NULL,
|
|
|
|
DocumentPath TEXT,
|
|
|
|
DocumentOwner VARCHAR(255) DEFAULT 'root',
|
|
|
|
DocumentGroup VARCHAR(255) DEFAULT 'root',
|
|
|
|
DocumentMode VARCHAR(10) DEFAULT '0644',
|
|
|
|
DocumentType VARCHAR(100) CHECK ( DocumentType IN ('probes', 'aggregated_dico', 'dico', 'template', 'pretemplate', 'posttemplate', 'preservice', 'postservice', 'creolefuncs', 'file') ),
|
|
|
|
DocumentSHASUM VARCHAR(255),
|
|
|
|
DocumentContent BYTEA,
|
|
|
|
FOREIGN KEY (DocumentServiceId) REFERENCES ApplicationService(ApplicationServiceId)
|
|
|
|
);
|
|
|
|
"""
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
db_conf = get_config().get('database')
|
|
|
|
pool = await asyncpg.create_pool(database=db_conf.get('dbname'), user=db_conf.get('user'))
|
|
|
|
async with pool.acquire() as connection:
|
|
|
|
async with connection.transaction():
|
|
|
|
returns = await connection.execute(VERSION_INIT)
|
2019-12-13 16:42:10 +01:00
|
|
|
|
2019-12-13 13:55:30 +01:00
|
|
|
asyncio.run(main())
|