local_<servermodel_name> application has to be created in internal source

This commit is contained in:
Emmanuel Garette 2019-12-16 16:17:27 +01:00
parent 91aac5399a
commit 7f0411da4d
3 changed files with 43 additions and 24 deletions

View File

@ -9,7 +9,7 @@ pattern: rpc
public: true
parameters:
sourceid:
source_id:
type: Number
shortarg: s
description: |

View File

@ -12,6 +12,17 @@ from ...error import ExecutionError
class Risotto(Controller):
async def on_join(self,
risotto_context: Context) -> None:
internal_source = await self.call('v1.source.create',
risotto_context,
source_name='internal',
source_url='none')
self.internal_release_id = await self.call('v1.source.release.create',
risotto_context,
source_id=internal_source['source_id'],
release_name='none')
async def _servermodel_create(self,
risotto_context: Context,
servermodel_name: str,
@ -27,7 +38,7 @@ class Risotto(Controller):
risotto_context,
applicationservice_name=as_name,
applicationservice_description=as_description,
release_id=release_id)
release_id=self.internal_release_id)
servermodel = await risotto_context.connection.fetchval(servermodel_update,
sm_name,
sm_description,
@ -118,7 +129,7 @@ class Risotto(Controller):
@register('v1.servermodel.list', None, database=True)
async def servermodel_list(self,
risotto_context: Context,
sourceid: int):
source_id: int):
sql = '''
SELECT ServermodelId as servermodel_id, ServermodelName as servermodel_name, ServermodelDescription as servermodel_description, ServermodelParentsId as servermodel_parents_id, ServermodelReleaseId as release_id FROM Servermodel
'''
@ -177,4 +188,4 @@ class Risotto(Controller):
<separators/>
</family>
</creole>"""
return {'servermodelid': 1, 'servermodelname': 'name', 'servermodeldescription': 'description', 'subreleasename': 'name', 'sourceid': 1, 'schema': schema, 'creolefuncs': ''}
return {'servermodelid': 1, 'servermodelname': 'name', 'servermodeldescription': 'description', 'subreleasename': 'name', 'source_id': 1, 'schema': schema, 'creolefuncs': ''}

View File

@ -3,24 +3,6 @@ from ...controller import Controller
from ...register import register
from ...context import Context
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)
);
"""
RELEASE_QUERY = """SELECT ReleaseId as release_id, SourceName as source_name, SourceURL as source_url, ReleaseName as release_name FROM Release, Source WHERE Source.SourceId=Release.ReleaseSourceId"""
class Risotto(Controller):
@register('v1.source.create', None, database=True)
@ -64,6 +46,7 @@ class Risotto(Controller):
risotto_context: Context,
source_id: int,
release_name: str):
# source.release.create is an upsert, do not using it
release_insert = """INSERT INTO Release(ReleaseName, ReleaseSourceId) VALUES ($1, $2)
RETURNING ReleaseId
"""
@ -73,7 +56,32 @@ class Risotto(Controller):
return {'release_id': release_id,
'release_name': release_name}
@register('v1.source.release.create', None, database=True)
async def source_release_create(self,
risotto_context: Context,
source_id: str,
release_name: str) -> Dict:
source_get = """SELECT SourceId as source_id, SourceName as source_name, SourceURL as source_url
FROM Source
WHERE SourceId = $1
"""
release_upsert = """INSERT INTO Release(ReleaseName, ReleaseSourceId) VALUES ($1, $2)
ON CONFLICT (ReleaseName, ReleaseSourceId) DO UPDATE SET ReleaseName = $1
RETURNING ReleaseId
"""
source = dict(await risotto_context.connection.fetchrow(source_get,
source_id))
release_id = await risotto_context.connection.fetchval(release_upsert,
release_name,
source_id)
del source['source_id']
source['release_id'] = release_id
source['release_name'] = release_name
return source
@register('v1.source.release.list', None, database=True)
async def release_list(self, risotto_context):
result = await risotto_context.connection.fetch(RELEASE_QUERY)
async def release_list(self,
risotto_context):
release_query = """SELECT ReleaseId as release_id, SourceName as source_name, SourceURL as source_url, ReleaseName as release_name FROM Release, Source WHERE Source.SourceId=Release.ReleaseSourceId"""
result = await risotto_context.connection.fetch(release_name)
return [dict(r) for r in result]