s
This commit is contained in:
@@ -333,6 +333,13 @@ COLLECTIONS: dict[str, list[dict[str, Any]]] = {
|
||||
number("durationMinutes", only_int=True),
|
||||
number("sortOrder", only_int=True),
|
||||
text("status", max=40),
|
||||
text("authorName", max=120),
|
||||
text("authorEmail", max=255),
|
||||
text("submittedBy", max=80),
|
||||
text("reviewStatus", max=40),
|
||||
text("reviewNote", max=1000),
|
||||
date("reviewedAt"),
|
||||
json_field("submissionMeta"),
|
||||
],
|
||||
"city_details": [
|
||||
text("citySlug", required=True, max=120),
|
||||
@@ -359,8 +366,26 @@ async def collection_exists(name: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
async def ensure_collection_fields(name: str, fields: list[dict[str, Any]]) -> None:
|
||||
collection = await pb.request("GET", f"/api/collections/{name}", admin=True)
|
||||
field_key = "fields" if "fields" in collection else "schema"
|
||||
current_fields = collection.get(field_key) or []
|
||||
current_names = {field.get("name") for field in current_fields}
|
||||
missing_fields = [field for field in fields if field.get("name") not in current_names]
|
||||
if not missing_fields:
|
||||
return
|
||||
await pb.request(
|
||||
"PATCH",
|
||||
f"/api/collections/{collection.get('id') or name}",
|
||||
admin=True,
|
||||
json={field_key: [*current_fields, *missing_fields]},
|
||||
)
|
||||
print(f"collection updated: {name} +{len(missing_fields)} fields")
|
||||
|
||||
|
||||
async def create_collection(name: str, fields: list[dict[str, Any]]) -> None:
|
||||
if await collection_exists(name):
|
||||
await ensure_collection_fields(name, fields)
|
||||
print(f"collection exists: {name}")
|
||||
return
|
||||
payload = {
|
||||
|
||||
Reference in New Issue
Block a user