Fixture import

This commit is contained in:
2023-01-25 16:41:47 +01:00
parent a2c930d457
commit b02c8cc365
4 changed files with 44 additions and 1 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,8 @@
.idea/ .idea/
*/__pycache__ */__pycache__
back/app/fixtures/
front/app-back/ front/app-back/
front/app-back2/ front/app-back2/
front/app-back3/ front/app-back3/

View File

41
back/migration.py Normal file
View File

@@ -0,0 +1,41 @@
import argparse
import asyncio
import json
from os import path
from app.db import init_db, Entity, Order, Contract, User, AccessToken
models = [Entity, Order, Contract, User]
async def handle_migration(args):
await init_db()
if args.action == "import-fixtures":
for m in models:
fname = './fixtures/{}.json'.format(m.__name__)
if path.isfile(fname):
with open(fname, 'r') as f:
content = json.load(f)
for r in content:
obj = m(**r)
obj.save()
elif args.action == "export-fixtures":
for m in models:
if await m.count() > 0:
with open('./fixtures/{}.json'.format(m.__name__), 'w') as f:
body = [o.json() for o in await m.find_all().to_list()]
f.write('[\n' + ',\n'.join(body) + '\n]\n')
if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog='migration.py',
description='Migrate data and schemas on the crud project',
epilog='Bisou')
parser.add_argument('action', type=str, help="The action to perform")
args = parser.parse_args()
asyncio.run(handle_migration(args))

View File

@@ -91,7 +91,7 @@ export class ForeignkeyTypeComponent extends FieldType<FieldTypeConfig> implemen
getList(term: string) : Observable<readonly string[]> { getList(term: string) : Observable<readonly string[]> {
return this.crudService.getList( return this.crudService.getList(
this.foreignResource, this.foreignResource,
0, 1,
10, 10,
[], [],
[new Filters('fulltext', 'eq', term)] [new Filters('fulltext', 'eq', term)]