Skip to content

Commit

Permalink
fix: export schema does not match import
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangSetSail committed Aug 2, 2023
1 parent dc96b87 commit 72f6f52
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion console/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Meta:
install_number = models.IntegerField(default=0, help_text='安装次数')
is_official = models.BooleanField(default=False, help_text='是否官方认证')
details = models.TextField(null=True, blank=True, help_text="应用详情")
arch = models.CharField(max_length=32, default="amd64", help_text="架构")
arch = models.CharField(max_length=32, help_text="架构")


class RainbondCenterAppVersion(BaseModel):
Expand Down
13 changes: 10 additions & 3 deletions console/services/app_import_and_export_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,17 @@ def __save_enterprise_import_info(self, import_record, metadata):
for app_template in metadata:
annotations = app_template.get("annotations", {})
app_describe = app_template.pop("describe", "")
apps = app_template.get("apps")
if annotations.get("describe", ""):
app_describe = annotations.pop("describe", "")
app = rainbond_app_repo.get_rainbond_app_by_app_id(import_record.enterprise_id, app_template["group_key"])
arch_map = {a.get("arch"): 1 for a in apps}
arch = "&".join(list(arch_map.keys()))
# if app exists, update it
if app:
app.scope = import_record.scope
app.describe = app_describe
app.arch = app.arch if arch in app.arch.split(",") else app.arch+","+arch
app.save()
app_version = rainbond_app_repo.get_rainbond_app_version_by_app_id_and_version(
app.app_id, app_template["group_version"])
Expand All @@ -460,10 +464,11 @@ def __save_enterprise_import_info(self, import_record, metadata):
app_version.template_version = app_template["template_version"]
app_version.app_version_info = version_info,
app_version.version_alias = version_alias,
app_version.arch = arch
app_version.save()
else:
# create a new version
rainbond_app_versions.append(self.create_app_version(app, import_record, app_template))
rainbond_app_versions.append(self.create_app_version(app, import_record, app_template, arch))
else:
image_base64_string = app_template.pop("image_base64_string", "")
if annotations.get("image_base64_string"):
Expand All @@ -487,15 +492,16 @@ def __save_enterprise_import_info(self, import_record, metadata):
scope=import_record.scope,
describe=app_describe,
pic=pic_url,
arch=arch
)
rainbond_apps.append(rainbond_app)
# create a new app version
rainbond_app_versions.append(self.create_app_version(rainbond_app, import_record, app_template))
rainbond_app_versions.append(self.create_app_version(rainbond_app, import_record, app_template, arch))
rainbond_app_repo.bulk_create_rainbond_app_versions(rainbond_app_versions)
rainbond_app_repo.bulk_create_rainbond_apps(rainbond_apps)

@staticmethod
def create_app_version(app, import_record, app_template):
def create_app_version(app, import_record, app_template, arch):
version = RainbondCenterAppVersion(
scope=import_record.scope,
enterprise_id=import_record.enterprise_id,
Expand All @@ -508,6 +514,7 @@ def create_app_version(app, import_record, app_template):
is_complete=1,
app_version_info=app_template.get("annotations", {}).get("version_info", ""),
version_alias=app_template.get("annotations", {}).get("version_alias", ""),
arch=arch,
)
if app_store.is_no_multiple_region_hub(import_record.enterprise_id):
version.region_name = import_record.region
Expand Down
11 changes: 7 additions & 4 deletions console/services/share_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,10 +912,13 @@ def create_share_info(self, tenant, region_name, share_record, share_team, share
app_version.region_name = region_name
app_version.save()
if not market_id:
arch = list(local_app_version.arch.split(","))
if app_version.arch not in arch:
arch.append(app_version.arch)
local_app_version.arch = ",".join(arch)
if local_app_version.arch:
arch = list(local_app_version.arch.split(","))
if app_version.arch not in arch:
arch.append(app_version.arch)
local_app_version.arch = ",".join(arch)
else:
local_app_version.arch = app_version.arch
local_app_version.save()
share_record.step = 2
share_record.scope = scope
Expand Down

0 comments on commit 72f6f52

Please sign in to comment.