Skip to content

Commit

Permalink
datahub removal p2
Browse files Browse the repository at this point in the history
  • Loading branch information
domdinicola committed Aug 26, 2024
1 parent e79542a commit 94e3bb7
Show file tree
Hide file tree
Showing 47 changed files with 29 additions and 112 deletions.
2 changes: 1 addition & 1 deletion backend/hct_mis_api/apps/account/export_users_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _add_headers(self) -> None:
for i in range(1, len(self.FIELDS_TO_COLUMNS_MAPPING) + 1):
self.ws.column_dimensions[get_column_letter(i)].width = 20

@transaction.atomic(using="default")
@transaction.atomic()
def get_exported_users_file(self) -> Optional[Workbook]:
fields = self.FIELDS_TO_COLUMNS_MAPPING.values()
users = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class TestAdminSite(WebTest):
"cash_assist_datahub_ca",
"cash_assist_datahub_erp",
"cash_assist_datahub_mis",
"registration_datahub",
]

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion backend/hct_mis_api/apps/cash_assist_datahub/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def simulate_import(self, request: "HttpRequest", pk: "UUID") -> Optional[Templa

runner = PullFromDatahubTask()
try:
with transaction.atomic(using="default"), transaction.atomic(using="cash_assist_datahub_ca"):
with transaction.atomic(), transaction.atomic(using="cash_assist_datahub_ca"):
runner.copy_session(session)
raise RollbackException()
except RollbackException:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def copy_session(self, session: "AbstractSession") -> None:
session.save(update_fields=("status",))
self.clear_cache(session)
try:
with transaction.atomic(using="default"), transaction.atomic(using="cash_assist_datahub_ca"):
with transaction.atomic(), transaction.atomic(using="cash_assist_datahub_ca"):
self.copy_service_providers(session)
self.copy_programs(session)
self.copy_target_population(session)
Expand Down
2 changes: 1 addition & 1 deletion backend/hct_mis_api/apps/core/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def create_target_population_task(self: Any, storage_id: str, program_id: str, t
set_sentry_business_area_tag(program.business_area.name)

try:
with transaction.atomic(), transaction.atomic("registration_datahub"):
with transaction.atomic():
registration_data_import = RegistrationDataImport.objects.create(
name=f"{storage_obj.file.name}_{program.name}",
number_of_individuals=0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ def handle(self, *args: Any, **options: Any) -> Any:
"targetpopulation",
],
"erp_datahub": ["downpayment", "fundscommitment"],
"registration_datahub": [
"importdata",
"importedindividualidentity",
"importeddocumenttype",
"importeddocument",
"importedhousehold",
"importedindividualroleinhousehold",
"importedindividual",
"koboimportedsubmission",
"record",
"registrationdataimportdatahub",
],
"mis_datahub": [
"document",
"downpayment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def handle(self, *args: Any, **options: Any) -> None:
call_command("flush", "--noinput", database="cash_assist_datahub_mis")
call_command("flush", "--noinput", database="cash_assist_datahub_ca")
call_command("flush", "--noinput", database="cash_assist_datahub_erp")
call_command("flush", "--noinput", database="registration_datahub")
call_command(
"loaddata",
"hct_mis_api/apps/account/fixtures/superuser.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@ def handle(self, *args: Any, **options: Any) -> None:
call_command("flush", "--noinput", database="cash_assist_datahub_mis")
call_command("flush", "--noinput", database="cash_assist_datahub_ca")
call_command("flush", "--noinput", database="cash_assist_datahub_erp")
call_command("flush", "--noinput", database="registration_datahub")

call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/geo/fixtures/data.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/core/fixtures/data.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/account/fixtures/data.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/program/fixtures/data-cypress.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/registration_data/fixtures/data-cypress.json")
call_command(
"loaddata",
f"{settings.PROJECT_ROOT}/apps/registration_datahub/fixtures/data-cypress.json",
database="registration_datahub",
)
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/household/fixtures/documenttype.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/household/fixtures/data-cypress.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/targeting/fixtures/data-cypress.json")
Expand Down
7 changes: 0 additions & 7 deletions backend/hct_mis_api/apps/core/management/commands/initdemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def handle(self, *args: Any, **options: Any) -> None:
call_command("flush", "--noinput", database="cash_assist_datahub_mis")
call_command("flush", "--noinput", database="cash_assist_datahub_ca")
call_command("flush", "--noinput", database="cash_assist_datahub_erp")
call_command("flush", "--noinput", database="registration_datahub")

call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/geo/fixtures/data.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/core/fixtures/data.json")
Expand All @@ -65,12 +64,6 @@ def handle(self, *args: Any, **options: Any) -> None:
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/household/fixtures/documenttype.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/household/fixtures/data.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/accountability/fixtures/data.json")

call_command(
"loaddata",
f"{settings.PROJECT_ROOT}/apps/registration_datahub/fixtures/data.json",
database="registration_datahub",
)
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/steficon/fixtures/data.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/aurora/fixtures/data.json")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class TestEdopomogaCreation(APITestCase):
databases = ("default", "registration_datahub", "cash_assist_datahub_mis")
databases = ("default", "cash_assist_datahub_mis")

@classmethod
def setUpTestData(cls) -> None:
Expand Down
4 changes: 2 additions & 2 deletions backend/hct_mis_api/apps/erp_datahub/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FundsCommitmentAdmin(HOPEModelAdminBase):
search_fields = ("rec_serial_number", "vendor_id", "wbs_element", "funds_commitment_number")

@atomic(using="cash_assist_datahub_erp")
@atomic(using="default")
@atomic()
@button(permission=should_show_assign_business_office)
def assign_business_office(
self, request: "HttpRequest", pk: "UUID"
Expand Down Expand Up @@ -224,7 +224,7 @@ class DownPaymentAdmin(HOPEModelAdminBase):
date_hierarchy = "create_date"

@atomic(using="cash_assist_datahub_erp")
@atomic(using="default")
@atomic()
@button(permission=should_show_assign_business_office)
def assign_business_office(
self, request: "HttpRequest", pk: "UUID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_model_dict(model: Model) -> Dict:
return model_dict

@atomic(using="cash_assist_datahub_erp")
@atomic(using="default")
@atomic()
def execute(self) -> None:
# have to be list because it used in another database

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


class DeduplicateAndCheckAgainstSanctionsListTask:
@transaction.atomic(using="default")
@transaction.atomic()
def execute(self, should_populate_index: bool, individuals_ids: List[str]) -> None:
individuals = Individual.objects.filter(id__in=individuals_ids)
business_area = individuals.first().business_area
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@


class TestAddIndividualService(BaseElasticSearchTestCase, TestCase):
databases = {"default", "registration_datahub"}

@classmethod
def setUpTestData(cls) -> None:
create_afghanistan()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@


class TestChangeIndividualRole(BaseElasticSearchTestCase, TestCase):
databases = {"default", "registration_datahub"}

@classmethod
def setUpTestData(cls) -> None:
business_area = BusinessAreaFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@


class TestUpdateIndividualDataService(BaseElasticSearchTestCase, TestCase):
databases = {"default", "registration_datahub"}

@classmethod
def setUpTestData(cls) -> None:
cls.business_area = BusinessAreaFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@


class TestChangeHeadOfHousehold(BaseElasticSearchTestCase, APITestCase):
databases = {"default", "registration_datahub"}

STATUS_CHANGE_MUTATION = """
mutation GrievanceStatusChange($grievanceTicketId: ID!, $status: Int) {
grievanceStatusChange(grievanceTicketId: $grievanceTicketId, status: $status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@

@flaky
class TestCloseDataChangeTickets(BaseElasticSearchTestCase, APITestCase):
databases = {"default", "registration_datahub"}

STATUS_CHANGE_MUTATION = """
mutation GrievanceStatusChange($grievanceTicketId: ID!, $status: Int) {
grievanceStatusChange(grievanceTicketId: $grievanceTicketId, status: $status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@


class TestCloseGrievanceTicketAndDisableDeduplication(BaseElasticSearchTestCase, APITestCase):
databases = {"default", "registration_datahub"}
fixtures = (f"{settings.PROJECT_ROOT}/apps/geo/fixtures/data.json",)

UPDATE_GRIEVANCE_TICKET_STATUS_CHANGE_MUTATION = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@


class TestGrievanceCreateDataChangeMutation(BaseElasticSearchTestCase, APITestCase):
databases = {"default", "registration_datahub"}

CREATE_DATA_CHANGE_GRIEVANCE_MUTATION = """
mutation createGrievanceTicket($input:CreateGrievanceTicketInput!){
createGrievanceTicket(input:$input){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


class TestHouseholdWithdraw(TestCase):
databases = {"registration_datahub", "default"}
fixtures = (f"{settings.PROJECT_ROOT}/apps/geo/fixtures/data.json",)

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@


class TestDocumentStatusFixer(TestCase):
databases = {"registration_datahub", "default"}

@classmethod
def setUpTestData(cls) -> None:
create_afghanistan()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def execute(self, target_population: "TargetPopulation") -> Dict:
target_population.save(update_fields=["status"])
return self.send_target_population(target_population)

@transaction.atomic(using="default")
@transaction.atomic()
@transaction.atomic(using="cash_assist_datahub_mis")
def send_target_population(self, target_population: "TargetPopulation") -> Dict:
households_to_bulk_create = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


class TestDataSendTpToDatahub(TestCase):
databases = {"default", "registration_datahub", "cash_assist_datahub_mis"}
databases = {"default", "cash_assist_datahub_mis"}

@staticmethod
def _pre_test_commands() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class TestExternalCollectorSendTpToDatahub(TestCase):
databases = {"default", "registration_datahub", "cash_assist_datahub_mis"}
databases = {"default", "cash_assist_datahub_mis"}

@staticmethod
def _pre_test_commands() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


class TestSendTpToDatahub(TestCase):
databases = {"default", "registration_datahub", "cash_assist_datahub_mis"}
databases = {"default", "cash_assist_datahub_mis"}

@staticmethod
def _pre_test_commands() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def rdi_deduplication_task(self: Any, registration_data_import_id: str) -> None:
rdi_obj = RegistrationDataImport.objects.get(id=registration_data_import_id)
program_id = rdi_obj.program.id
set_sentry_business_area_tag(rdi_obj.business_area.slug)
with transaction.atomic(using="default"), transaction.atomic(using="registration_datahub"):
with transaction.atomic():
DeduplicateTask(rdi_obj.business_area.slug, program_id).deduplicate_pending_individuals(
registration_data_import=rdi_obj
)
Expand Down
25 changes: 9 additions & 16 deletions backend/hct_mis_api/apps/registration_datahub/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
logger = logging.getLogger(__name__)


@transaction.atomic(using="default")
@transaction.atomic(using="registration_datahub")
@transaction.atomic()
def create_registration_data_import_objects(
registration_data_import_data: Dict,
user: "User",
Expand Down Expand Up @@ -102,8 +101,7 @@ def create_registration_data_import_objects(
)


@transaction.atomic(using="default")
@transaction.atomic(using="registration_datahub")
@transaction.atomic()
def create_registration_data_import_for_import_program_population(
registration_data_import_data: Dict,
user: "User",
Expand Down Expand Up @@ -164,8 +162,7 @@ def validate_import_data(
raise ValidationError("Cannot import empty form")

@classmethod
@transaction.atomic(using="default")
@transaction.atomic(using="registration_datahub")
@transaction.atomic()
@is_authenticated
def processed_mutate(
cls, root: Any, info: Any, registration_data_import_data: Dict
Expand Down Expand Up @@ -229,8 +226,7 @@ class Arguments:
registration_data_import_data = RegistrationProgramPopulationImportMutationInput(required=True)

@classmethod
@transaction.atomic(using="default")
@transaction.atomic(using="registration_datahub")
@transaction.atomic()
@is_authenticated
def processed_mutate(
cls, root: Any, info: Any, registration_data_import_data: Dict
Expand Down Expand Up @@ -335,8 +331,7 @@ class Arguments:
registration_data_import_data = RegistrationKoboImportMutationInput(required=True)

@classmethod
@transaction.atomic(using="default")
@transaction.atomic(using="registration_datahub")
@transaction.atomic()
@is_authenticated
def processed_mutate(
cls, root: Any, info: Any, registration_data_import_data: Dict
Expand Down Expand Up @@ -398,8 +393,7 @@ class Arguments:
version = BigInt(required=False)

@classmethod
@transaction.atomic(using="default")
@transaction.atomic(using="registration_datahub")
@transaction.atomic()
@is_authenticated
@raise_program_status_is(Program.FINISHED)
def mutate(cls, root: Any, info: Any, id: Optional[str], **kwargs: Any) -> "MergeRegistrationDataImportMutation":
Expand Down Expand Up @@ -447,7 +441,7 @@ def validate_object_status(cls, *args: Any, **kwargs: Any) -> None:
raise ValidationError("Only In Review Registration Data Import can be refused")

@classmethod
@transaction.atomic(using="default")
@transaction.atomic()
@is_authenticated
@raise_program_status_is(Program.FINISHED)
def mutate(cls, root: Any, info: Any, id: Optional[str], **kwargs: Any) -> "RefuseRegistrationDataImportMutation":
Expand Down Expand Up @@ -492,7 +486,7 @@ class Arguments:
version = BigInt(required=False)

@classmethod
@transaction.atomic(using="default")
@transaction.atomic()
@is_authenticated
@raise_program_status_is(Program.FINISHED)
def mutate(cls, root: Any, info: Any, id: Optional[str], **kwargs: Any) -> "EraseRegistrationDataImportMutation":
Expand Down Expand Up @@ -538,8 +532,7 @@ class Arguments:
business_area_slug = graphene.String(required=True)

@classmethod
@transaction.atomic(using="default")
@transaction.atomic(using="registration_datahub")
@transaction.atomic()
@is_authenticated
def mutate(cls, root: Any, info: Any, file: IO, business_area_slug: str) -> "UploadImportDataXLSXFileAsync":
cls.has_permission(info, Permissions.RDI_IMPORT_DATA, business_area_slug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@


class PullKoboSubmissions:
@transaction.atomic(using="default")
@transaction.atomic(using="registration_datahub")
@transaction.atomic()
def execute(self, kobo_import_data: KoboImportData, program: Program) -> Dict:
kobo_import_data.status = KoboImportData.STATUS_RUNNING
kobo_import_data.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def execute(self, registration_data_import_id: str) -> None:
individual_ids = list(individuals.values_list("id", flat=True))
household_ids = list(households.values_list("id", flat=True))
try:
with transaction.atomic(using="default"):
with transaction.atomic():
old_obj_hct = copy_model_object(obj_hct)

transaction.on_commit(lambda: recalculate_population_fields_task(household_ids, obj_hct.program_id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class ValidateXlsxImport:
@transaction.atomic(using="default")
@transaction.atomic()
def execute(self, import_data: ImportData, program: Program) -> Dict:
import_data.status = ImportData.STATUS_RUNNING
import_data.save()
Expand Down
Loading

0 comments on commit 94e3bb7

Please sign in to comment.