diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index 71b2323b..f20eb455 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -49,12 +49,25 @@ export class Database { await this.dataSource.initialize(); log('database initialized'); - const organizations = await this.getOrganizations({}); + let organizations = await this.getOrganizations({}); // Load an organization if none exist if (!organizations.length) { const orgEntities = await getEntities(path.resolve(__dirname, ORGANIZATION_DATA_PATH)); - await loadAndSaveData(Organization, this.dataSource, [orgEntities[0]]); + organizations = await loadAndSaveData(Organization, this.dataSource, [orgEntities[0]]); + } + + // Hotfix for updating old DB data + if (organizations[0].slug === 'snowball-tools-1') { + const [orgEntity] = await getEntities(path.resolve(__dirname, ORGANIZATION_DATA_PATH)); + + await this.updateOrganization( + organizations[0].id, + { + slug: orgEntity.slug as string, + name: orgEntity.name as string + } + ) } } @@ -121,6 +134,14 @@ export class Database { return newUserOrganization; } + async updateOrganization(organizationId: string, data: DeepPartial): Promise { + const organizationRepository = this.dataSource.getRepository(Organization); + const updateResult = await organizationRepository.update({ id: organizationId }, data); + assert(updateResult.affected); + + return updateResult.affected > 0; + } + async getProjects(options: FindManyOptions): Promise { const projectRepository = this.dataSource.getRepository(Project); const projects = await projectRepository.find(options); diff --git a/packages/deployer/deploy-frontend.sh b/packages/deployer/deploy-frontend.sh index 5f843981..83c42887 100755 --- a/packages/deployer/deploy-frontend.sh +++ b/packages/deployer/deploy-frontend.sh @@ -8,8 +8,11 @@ echo "Using AUTHORITY: $AUTHORITY" # Repository URL REPO_URL="https://git.vdb.to/cerc-io/snowballtools-base" -# Get the latest commit hash from the repository -LATEST_HASH=$(git ls-remote $REPO_URL HEAD | awk '{print $1}') +# Get the latest commit hash for a branch +BRANCH_NAME="main" +LATEST_HASH=$(git ls-remote $REPO_URL refs/heads/$BRANCH_NAME | awk '{print $1}') + +echo "Latest commit hash for branch $BRANCH_NAME: $LATEST_HASH" # Extract version from ../frontend/package.json PACKAGE_VERSION=$(jq -r '.version' ../frontend/package.json) diff --git a/packages/deployer/remove-deployment.sh b/packages/deployer/remove-deployment.sh new file mode 100755 index 00000000..f767bb61 --- /dev/null +++ b/packages/deployer/remove-deployment.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +source .env +echo "Using REGISTRY_BOND_ID: $REGISTRY_BOND_ID" +echo "Using DEPLOYER_LRN: $DEPLOYER_LRN" + +# Generate application-deployment-removal-request.yml +REMOVAL_REQUEST_RECORD_FILE=records/application-deployment-removal-request.yml +# TODO: Pass deployment record ID as arg +DEPLOYMENT_RECORD_ID=bafyreidjho77xeczaqpyawhc4wbpm5it5atibtuxk6ost6vnpu2svlp3ka + +cat > $REMOVAL_REQUEST_RECORD_FILE <