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