From dec8e3459aded0cb62c1d461eb6161e6ff31fea6 Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Thu, 14 Jul 2022 10:54:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Oracle=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=20version=20=E8=BF=81=E7=A7=BB=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=BB=98=E8=AE=A4=2012c=20=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: 添加 Oracle 数据库 version 迁移文件默认 12c 版本 --- .../migrations/0022_auto_20220714_1046.py | 23 +++++++++++++++++++ apps/applications/models/application.py | 2 +- .../attrs/application_type/oracle.py | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 apps/applications/migrations/0022_auto_20220714_1046.py diff --git a/apps/applications/migrations/0022_auto_20220714_1046.py b/apps/applications/migrations/0022_auto_20220714_1046.py new file mode 100644 index 000000000..8ecb1cbe6 --- /dev/null +++ b/apps/applications/migrations/0022_auto_20220714_1046.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.12 on 2022-07-14 02:46 + +from django.db import migrations + + +def migrate_db_oracle_version_to_attrs(apps, schema_editor): + db_alias = schema_editor.connection.alias + model = apps.get_model("applications", "Application") + oracles = list(model.objects.using(db_alias).filter(type='oracle')) + for o in oracles: + o.attrs['version'] = '12c' + model.objects.using(db_alias).bulk_update(oracles, ['attrs']) + + +class Migration(migrations.Migration): + + dependencies = [ + ('applications', '0021_auto_20220629_1826'), + ] + + operations = [ + migrations.RunPython(migrate_db_oracle_version_to_attrs) + ] diff --git a/apps/applications/models/application.py b/apps/applications/models/application.py index 1644ab1d5..cc98abaf8 100644 --- a/apps/applications/models/application.py +++ b/apps/applications/models/application.py @@ -308,7 +308,7 @@ class Application(CommonModelMixin, OrgModelMixin, ApplicationTreeNodeMixin): """ Oracle 类型需要单独处理,因为要携带版本号 """ if not self.is_type(self.APP_TYPE.oracle): return - version = self.attrs.get('version', OracleVersion.version_other) + version = self.attrs.get('version', OracleVersion.version_12c) if version == OracleVersion.version_other: return return 'oracle_%s' % version diff --git a/apps/applications/serializers/attrs/application_type/oracle.py b/apps/applications/serializers/attrs/application_type/oracle.py index 94cfaa319..fdc8016d2 100644 --- a/apps/applications/serializers/attrs/application_type/oracle.py +++ b/apps/applications/serializers/attrs/application_type/oracle.py @@ -9,7 +9,7 @@ __all__ = ['OracleSerializer'] class OracleSerializer(DBSerializer): version = serializers.ChoiceField( - choices=OracleVersion.choices, default=OracleVersion.version_other, + choices=OracleVersion.choices, default=OracleVersion.version_12c, allow_null=True, label=_('Version'), help_text=_('Magnus currently supports only 11g and 12c connections') )