kopia lustrzana https://github.com/bugout-dev/moonstream
Add checkpoints and add cli migration id.
fix: path to json migration files folder.pull/758/head
rodzic
7287e800b8
commit
cd541cbb74
|
@ -16,13 +16,17 @@ from ..settings import BUGOUT_BROOD_URL, BUGOUT_SPIRE_URL, MOONSTREAM_APPLICATIO
|
|||
from ..web3_provider import yield_web3_provider
|
||||
|
||||
from . import subscription_types, subscriptions, moonworm_tasks
|
||||
from .migrations import checksum_address, update_dashboard_subscription_key
|
||||
from .migrations import (
|
||||
checksum_address,
|
||||
update_dashboard_subscription_key,
|
||||
generate_entity_subscriptions,
|
||||
)
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MIGRATIONS_FOLDER = "./moonstream/admin/migrations"
|
||||
MIGRATIONS_FOLDER = "./moonstreamapi/admin/migrations"
|
||||
|
||||
|
||||
def parse_boolean_arg(raw_arg: Optional[str]) -> Optional[bool]:
|
||||
|
@ -43,6 +47,14 @@ name: {checksum_address.__name__}
|
|||
description: {checksum_address.__doc__}
|
||||
"""
|
||||
logger.info(migrations_overview)
|
||||
|
||||
entity_migration_overview = f"""
|
||||
- id: 20230213
|
||||
name: {generate_entity_subscriptions.__name__}
|
||||
description: {generate_entity_subscriptions.__doc__}
|
||||
"""
|
||||
logger.info(entity_migration_overview)
|
||||
|
||||
json_migrations_oreview = "Available migrations files."
|
||||
for file in os.listdir(MIGRATIONS_FOLDER):
|
||||
if file.endswith(".json"):
|
||||
|
@ -71,10 +83,8 @@ def migrations_run(args: argparse.Namespace) -> None:
|
|||
db_session = SessionLocal()
|
||||
try:
|
||||
if args.id == 20230213:
|
||||
logger.info("Starting update of subscriptions in Brood resource...")
|
||||
checksum_address.checksum_all_subscription_addresses(web3_session)
|
||||
logger.info("Starting update of ethereum_labels in database...")
|
||||
checksum_address.checksum_all_labels_addresses(db_session, web3_session)
|
||||
logger.info("Starting migrate subscriptions from resources to entity...")
|
||||
generate_entity_subscriptions.Generate_entity_subscriptions_from_brood_resources()
|
||||
elif args.id == 20211101:
|
||||
logger.info("Starting update of subscriptions in Brood resource...")
|
||||
checksum_address.checksum_all_subscription_addresses(web3_session)
|
||||
|
@ -82,7 +92,7 @@ def migrations_run(args: argparse.Namespace) -> None:
|
|||
checksum_address.checksum_all_labels_addresses(db_session, web3_session)
|
||||
elif args.id == 20211202:
|
||||
update_dashboard_subscription_key.update_dashboard_resources_key()
|
||||
else:
|
||||
elif args.id == 20211108:
|
||||
drop_keys = []
|
||||
|
||||
if args.file is not None:
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
"""
|
||||
Convert all addresses in user subscriptions
|
||||
and ethereum_labels column to checksum address.
|
||||
Generate entity subscriptions from existing brood resources subscriptions
|
||||
"""
|
||||
import hashlib
|
||||
import logging
|
||||
import json
|
||||
from pprint import pprint
|
||||
from typing import List, Optional, Dict, Any, Union
|
||||
import uuid
|
||||
|
||||
|
@ -157,6 +157,10 @@ def Generate_entity_subscriptions_from_brood_resources() -> None:
|
|||
|
||||
for resource in resources.resources:
|
||||
|
||||
pprint(resource)
|
||||
|
||||
raise Exception("Stop")
|
||||
|
||||
resource_data = resource.resource_data
|
||||
|
||||
resource_data["subscription_id"] = resource.id
|
||||
|
@ -175,6 +179,9 @@ def Generate_entity_subscriptions_from_brood_resources() -> None:
|
|||
|
||||
users_subscriptions[user_id].append(resource_data)
|
||||
|
||||
print(f"parsed subscriptions: {len(users_subscriptions)}")
|
||||
|
||||
raise Exception("Stop")
|
||||
# Start proccessing users subscriptions
|
||||
|
||||
try:
|
||||
|
@ -234,7 +241,7 @@ def Generate_entity_subscriptions_from_brood_resources() -> None:
|
|||
label = subscription["label"]
|
||||
|
||||
# try to get abi from S3
|
||||
|
||||
abi = None
|
||||
if resource_data["bucket"] and resource_data["s3_path"]:
|
||||
try:
|
||||
abi = get_abi_from_s3(
|
||||
|
@ -254,34 +261,37 @@ def Generate_entity_subscriptions_from_brood_resources() -> None:
|
|||
address=address,
|
||||
color=color,
|
||||
label=label,
|
||||
content=abi if abi else {},
|
||||
content={"abi": abi, "abi_hash": abi_hash} if abi else {},
|
||||
)
|
||||
|
||||
stages[user_id]["proccessed_subscriptions"].append(subscription["id"])
|
||||
|
||||
# Add permissions to user
|
||||
|
||||
try:
|
||||
if "permissions_granted" not in stages[user_id]:
|
||||
try:
|
||||
|
||||
add_collection_permissions_to_user(
|
||||
user_id=user_id,
|
||||
collection_id=collection_id,
|
||||
permissions=["read", "update"],
|
||||
)
|
||||
stages[user_id]["permissions_granted"] = True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to add permissions to user: {str(e)}")
|
||||
add_collection_permissions_to_user(
|
||||
user_id=user_id,
|
||||
collection_id=collection_id,
|
||||
permissions=["read", "update"],
|
||||
)
|
||||
stages[user_id]["permissions_granted"] = True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to add permissions to user: {str(e)}")
|
||||
continue
|
||||
|
||||
# Remove permissions from user
|
||||
try:
|
||||
revoke_collection_permissions_from_user(
|
||||
user_id=admin_user_id,
|
||||
collection_id=collection_id,
|
||||
permissions=["read", "update"],
|
||||
)
|
||||
stages[user_id]["permissions_revoked"] = True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to revoke permissions from user: {str(e)}")
|
||||
if "permissions_revoked" not in stages[user_id]:
|
||||
try:
|
||||
revoke_collection_permissions_from_user(
|
||||
user_id=admin_user_id,
|
||||
collection_id=collection_id,
|
||||
permissions=["read", "update"],
|
||||
)
|
||||
stages[user_id]["permissions_revoked"] = True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to revoke permissions from user: {str(e)}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to proccess user subscriptions: {str(e)}")
|
||||
finally:
|
||||
|
|
Ładowanie…
Reference in New Issue