Fixture import
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -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/
|
||||||
|
|||||||
0
back/app/fixtures/git.keep
Normal file
0
back/app/fixtures/git.keep
Normal file
41
back/migration.py
Normal file
41
back/migration.py
Normal 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))
|
||||||
@@ -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)]
|
||||||
|
|||||||
Reference in New Issue
Block a user