mysql --> mssql
Showing
5 changed files
with
461 additions
and
22 deletions
... | @@ -7,7 +7,7 @@ from .named_enum import DocStatus, KeywordsType | ... | @@ -7,7 +7,7 @@ from .named_enum import DocStatus, KeywordsType |
7 | # 上传文件记录表/任务表 | 7 | # 上传文件记录表/任务表 |
8 | class UploadDocRecords(models.Model): | 8 | class UploadDocRecords(models.Model): |
9 | id = models.AutoField(primary_key=True, verbose_name="id") | 9 | id = models.AutoField(primary_key=True, verbose_name="id") |
10 | metadata_version_id = models.CharField(max_length=64, verbose_name="元数据版本id") | 10 | metadata_version_id = models.CharField(max_length=64, verbose_name="元数据版本id") # 索引 |
11 | application_id = models.CharField(max_length=64, verbose_name="申请id") | 11 | application_id = models.CharField(max_length=64, verbose_name="申请id") |
12 | main_applicant = models.CharField(max_length=16, verbose_name="主申请人") | 12 | main_applicant = models.CharField(max_length=16, verbose_name="主申请人") |
13 | co_applicant = models.CharField(max_length=16, verbose_name="共同申请人") | 13 | co_applicant = models.CharField(max_length=16, verbose_name="共同申请人") |
... | @@ -28,7 +28,6 @@ class UploadDocRecords(models.Model): | ... | @@ -28,7 +28,6 @@ class UploadDocRecords(models.Model): |
28 | 28 | ||
29 | class HILDoc(models.Model): | 29 | class HILDoc(models.Model): |
30 | id = models.AutoField(primary_key=True, verbose_name="id") | 30 | id = models.AutoField(primary_key=True, verbose_name="id") |
31 | record_id = models.IntegerField(verbose_name='记录id') | ||
32 | metadata_version_id = models.CharField(max_length=64, verbose_name="元数据版本id") | 31 | metadata_version_id = models.CharField(max_length=64, verbose_name="元数据版本id") |
33 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 联合索引 | 32 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 联合索引 |
34 | status = models.SmallIntegerField(default=DocStatus.INIT.value, verbose_name="文件状态") # 联合索引 | 33 | status = models.SmallIntegerField(default=DocStatus.INIT.value, verbose_name="文件状态") # 联合索引 |
... | @@ -50,7 +49,6 @@ class HILDoc(models.Model): | ... | @@ -50,7 +49,6 @@ class HILDoc(models.Model): |
50 | 49 | ||
51 | class AFCDoc(models.Model): | 50 | class AFCDoc(models.Model): |
52 | id = models.AutoField(primary_key=True, verbose_name="id") | 51 | id = models.AutoField(primary_key=True, verbose_name="id") |
53 | record_id = models.IntegerField(verbose_name='记录id') | ||
54 | metadata_version_id = models.CharField(max_length=64, verbose_name="元数据版本id") | 52 | metadata_version_id = models.CharField(max_length=64, verbose_name="元数据版本id") |
55 | application_id = models.CharField(max_length=64, verbose_name="申请id") | 53 | application_id = models.CharField(max_length=64, verbose_name="申请id") |
56 | status = models.SmallIntegerField(default=DocStatus.INIT.value, verbose_name="文件状态") | 54 | status = models.SmallIntegerField(default=DocStatus.INIT.value, verbose_name="文件状态") |
... | @@ -76,7 +74,7 @@ class GCAPRecords(models.Model): | ... | @@ -76,7 +74,7 @@ class GCAPRecords(models.Model): |
76 | status = models.IntegerField(null=True, verbose_name='状态') | 74 | status = models.IntegerField(null=True, verbose_name='状态') |
77 | rating = models.IntegerField(null=True, verbose_name='排名') | 75 | rating = models.IntegerField(null=True, verbose_name='排名') |
78 | entity = models.CharField(null=True, max_length=128, verbose_name="业务类型") | 76 | entity = models.CharField(null=True, max_length=128, verbose_name="业务类型") |
79 | application_id = models.CharField(max_length=128, verbose_name="申请id") | 77 | application_id = models.CharField(max_length=64, verbose_name="申请id") |
80 | application_version = models.IntegerField(null=True, verbose_name='申请版本') | 78 | application_version = models.IntegerField(null=True, verbose_name='申请版本') |
81 | intermediate_decision = models.CharField(null=True, max_length=128, verbose_name="中间决策") | 79 | intermediate_decision = models.CharField(null=True, max_length=128, verbose_name="中间决策") |
82 | submit_datetime = models.DateTimeField(null=True, verbose_name='提交时间') | 80 | submit_datetime = models.DateTimeField(null=True, verbose_name='提交时间') | ... | ... |
... | @@ -106,7 +106,7 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -106,7 +106,7 @@ class UploadDocView(GenericView, DocHandler): |
106 | data_source = document.get('dataSource') | 106 | data_source = document.get('dataSource') |
107 | try: | 107 | try: |
108 | # 1. 上传信息记录 | 108 | # 1. 上传信息记录 |
109 | record = UploadDocRecords.objects.create( | 109 | UploadDocRecords.objects.create( |
110 | metadata_version_id=document.get('metadataVersionId'), | 110 | metadata_version_id=document.get('metadataVersionId'), |
111 | application_id=application_id, | 111 | application_id=application_id, |
112 | main_applicant=applicant_data.get('mainApplicantName'), | 112 | main_applicant=applicant_data.get('mainApplicantName'), |
... | @@ -126,7 +126,6 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -126,7 +126,6 @@ class UploadDocView(GenericView, DocHandler): |
126 | # 2. 根据业务类型分库存储 | 126 | # 2. 根据业务类型分库存储 |
127 | doc_class, prefix = self.get_doc_class(business_type) | 127 | doc_class, prefix = self.get_doc_class(business_type) |
128 | doc = doc_class.objects.create( | 128 | doc = doc_class.objects.create( |
129 | record_id=record.id, | ||
130 | metadata_version_id=document.get('metadataVersionId'), | 129 | metadata_version_id=document.get('metadataVersionId'), |
131 | application_id=application_id, | 130 | application_id=application_id, |
132 | main_applicant=applicant_data.get('mainApplicantName'), | 131 | main_applicant=applicant_data.get('mainApplicantName'), |
... | @@ -142,8 +141,8 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -142,8 +141,8 @@ class UploadDocView(GenericView, DocHandler): |
142 | is_priority = PriorityApplication.objects.filter(application_id=application_id, on_off=True).exists() | 141 | is_priority = PriorityApplication.objects.filter(application_id=application_id, on_off=True).exists() |
143 | tasks = ['{0}{1}{2}'.format(prefix, consts.SPLIT_STR, doc.id)] | 142 | tasks = ['{0}{1}{2}'.format(prefix, consts.SPLIT_STR, doc.id)] |
144 | enqueue_res = rh.enqueue(tasks, is_priority) | 143 | enqueue_res = rh.enqueue(tasks, is_priority) |
145 | self.running_log.info('[doc upload success] [args={0}] [record_id={1}] [business_type={2}] [doc_id={3}] ' | 144 | self.running_log.info('[doc upload success] [args={0}] [business_type={1}] [doc_id={2}] ' |
146 | '[is_priority={4}] [enqueue_res={5}]'.format(args, record.id, prefix, doc.id, | 145 | '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id, |
147 | is_priority, enqueue_res)) | 146 | is_priority, enqueue_res)) |
148 | return response.ok() | 147 | return response.ok() |
149 | 148 | ||
... | @@ -279,7 +278,7 @@ class DocView(GenericView, DocHandler): | ... | @@ -279,7 +278,7 @@ class DocView(GenericView, DocHandler): |
279 | document_scheme = random.choice(consts.DOC_SCHEME_LIST) | 278 | document_scheme = random.choice(consts.DOC_SCHEME_LIST) |
280 | data_source = random.choice(consts.DATA_SOURCE_LIST) | 279 | data_source = random.choice(consts.DATA_SOURCE_LIST) |
281 | business_type = random.choice(consts.BUSINESS_TYPE_LIST) | 280 | business_type = random.choice(consts.BUSINESS_TYPE_LIST) |
282 | record = UploadDocRecords.objects.create( | 281 | UploadDocRecords.objects.create( |
283 | metadata_version_id=metadata_version_id, | 282 | metadata_version_id=metadata_version_id, |
284 | application_id=application_id, | 283 | application_id=application_id, |
285 | main_applicant='', | 284 | main_applicant='', |
... | @@ -296,7 +295,6 @@ class DocView(GenericView, DocHandler): | ... | @@ -296,7 +295,6 @@ class DocView(GenericView, DocHandler): |
296 | # 2. 根据业务类型分库存储 | 295 | # 2. 根据业务类型分库存储 |
297 | doc_class, prefix = self.get_doc_class(business_type) | 296 | doc_class, prefix = self.get_doc_class(business_type) |
298 | doc = doc_class.objects.create( | 297 | doc = doc_class.objects.create( |
299 | record_id=record.id, | ||
300 | metadata_version_id=metadata_version_id, | 298 | metadata_version_id=metadata_version_id, |
301 | application_id=application_id, | 299 | application_id=application_id, |
302 | main_applicant='', | 300 | main_applicant='', |
... | @@ -319,7 +317,7 @@ class DocView(GenericView, DocHandler): | ... | @@ -319,7 +317,7 @@ class DocView(GenericView, DocHandler): |
319 | os.makedirs(save_dir_path, exist_ok=True) | 317 | os.makedirs(save_dir_path, exist_ok=True) |
320 | file_write(pdf_file, save_file_path) | 318 | file_write(pdf_file, save_file_path) |
321 | 319 | ||
322 | self.running_log.info('[mock doc upload success] [args={0}] [record_id={1}] [business_type={2}] [doc_id={3}] ' | 320 | self.running_log.info('[mock doc upload success] [args={0}] [business_type={1}] [doc_id={2}] ' |
323 | '[is_priority={4}] [enqueue_res={5}]'.format(args, record.id, prefix, doc.id, | 321 | '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id, |
324 | is_priority, enqueue_res)) | 322 | is_priority, enqueue_res)) |
325 | return response.ok() | 323 | return response.ok() | ... | ... |
src/common/tools/mssql_script.py
0 → 100644
1 | import pyodbc | ||
2 | |||
3 | cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=47.97.220.40;UID=SA;PWD=19951019Mssql', autocommit=True) | ||
4 | |||
5 | cursor = cnxn.cursor() | ||
6 | cursor.execute("create database afc") | ||
7 | cursor.execute("create database hil") | ||
8 | |||
9 | cursor.close() | ||
10 | cnxn.close() | ||
11 | |||
12 | hil_sql_1 = """ | ||
13 | create table auth_group | ||
14 | ( | ||
15 | id int identity | ||
16 | primary key, | ||
17 | name nvarchar(150) not null | ||
18 | constraint auth_group_name_a6ea08ec_uniq | ||
19 | unique | ||
20 | ); | ||
21 | |||
22 | create table auth_user | ||
23 | ( | ||
24 | id int identity | ||
25 | primary key, | ||
26 | password nvarchar(128) not null, | ||
27 | last_login datetime2, | ||
28 | is_superuser bit not null, | ||
29 | username nvarchar(150) not null | ||
30 | constraint auth_user_username_6821ab7c_uniq | ||
31 | unique, | ||
32 | first_name nvarchar(30) not null, | ||
33 | last_name nvarchar(150) not null, | ||
34 | email nvarchar(254) not null, | ||
35 | is_staff bit not null, | ||
36 | is_active bit not null, | ||
37 | date_joined datetime2 not null | ||
38 | ); | ||
39 | |||
40 | create table auth_user_groups | ||
41 | ( | ||
42 | id int identity | ||
43 | primary key, | ||
44 | user_id int not null | ||
45 | constraint auth_user_groups_user_id_6a12ed8b_fk_auth_user_id | ||
46 | references auth_user, | ||
47 | group_id int not null | ||
48 | constraint auth_user_groups_group_id_97559544_fk_auth_group_id | ||
49 | references auth_group | ||
50 | ); | ||
51 | |||
52 | create unique index auth_user_groups_user_id_group_id_94350c0c_uniq | ||
53 | on auth_user_groups (user_id, group_id) | ||
54 | where [user_id] IS NOT NULL AND [group_id] IS NOT NULL; | ||
55 | |||
56 | create index auth_user_groups_group_id_97559544 | ||
57 | on auth_user_groups (group_id); | ||
58 | |||
59 | create index auth_user_groups_user_id_6a12ed8b | ||
60 | on auth_user_groups (user_id); | ||
61 | |||
62 | create table django_content_type | ||
63 | ( | ||
64 | id int identity | ||
65 | primary key, | ||
66 | app_label nvarchar(100) not null, | ||
67 | model nvarchar(100) not null | ||
68 | ); | ||
69 | |||
70 | create table auth_permission | ||
71 | ( | ||
72 | id int identity | ||
73 | primary key, | ||
74 | name nvarchar(255) not null, | ||
75 | content_type_id int not null | ||
76 | constraint auth_permission_content_type_id_2f476e4b_fk_django_content_type_id | ||
77 | references django_content_type, | ||
78 | codename nvarchar(100) not null | ||
79 | ); | ||
80 | |||
81 | create table auth_group_permissions | ||
82 | ( | ||
83 | id int identity | ||
84 | primary key, | ||
85 | group_id int not null | ||
86 | constraint auth_group_permissions_group_id_b120cbf9_fk_auth_group_id | ||
87 | references auth_group, | ||
88 | permission_id int not null | ||
89 | constraint auth_group_permissions_permission_id_84c5c92e_fk_auth_permission_id | ||
90 | references auth_permission | ||
91 | ); | ||
92 | |||
93 | create index auth_group_permissions_permission_id_84c5c92e | ||
94 | on auth_group_permissions (permission_id); | ||
95 | |||
96 | create index auth_group_permissions_group_id_b120cbf9 | ||
97 | on auth_group_permissions (group_id); | ||
98 | |||
99 | create unique index auth_group_permissions_group_id_permission_id_0cd325b0_uniq | ||
100 | on auth_group_permissions (group_id, permission_id) | ||
101 | where [group_id] IS NOT NULL AND [permission_id] IS NOT NULL; | ||
102 | |||
103 | create index auth_permission_content_type_id_2f476e4b | ||
104 | on auth_permission (content_type_id); | ||
105 | |||
106 | create unique index auth_permission_content_type_id_codename_01ab375a_uniq | ||
107 | on auth_permission (content_type_id, codename) | ||
108 | where [content_type_id] IS NOT NULL AND [codename] IS NOT NULL; | ||
109 | |||
110 | create table auth_user_user_permissions | ||
111 | ( | ||
112 | id int identity | ||
113 | primary key, | ||
114 | user_id int not null | ||
115 | constraint auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id | ||
116 | references auth_user, | ||
117 | permission_id int not null | ||
118 | constraint auth_user_user_permissions_permission_id_1fbb5f2c_fk_auth_permission_id | ||
119 | references auth_permission | ||
120 | ); | ||
121 | |||
122 | create index auth_user_user_permissions_permission_id_1fbb5f2c | ||
123 | on auth_user_user_permissions (permission_id); | ||
124 | |||
125 | create index auth_user_user_permissions_user_id_a95ead1b | ||
126 | on auth_user_user_permissions (user_id); | ||
127 | |||
128 | create unique index auth_user_user_permissions_user_id_permission_id_14a6b632_uniq | ||
129 | on auth_user_user_permissions (user_id, permission_id) | ||
130 | where [user_id] IS NOT NULL AND [permission_id] IS NOT NULL; | ||
131 | |||
132 | create table django_admin_log | ||
133 | ( | ||
134 | id int identity | ||
135 | primary key, | ||
136 | action_time datetime2 not null, | ||
137 | object_id nvarchar(max), | ||
138 | object_repr nvarchar(200) not null, | ||
139 | action_flag smallint not null | ||
140 | constraint django_admin_log_action_flag_a8637d59_check | ||
141 | check ([action_flag] >= 0), | ||
142 | change_message nvarchar(max) not null, | ||
143 | content_type_id int | ||
144 | constraint django_admin_log_content_type_id_c4bce8eb_fk_django_content_type_id | ||
145 | references django_content_type, | ||
146 | user_id int not null | ||
147 | constraint django_admin_log_user_id_c564eba6_fk_auth_user_id | ||
148 | references auth_user | ||
149 | ); | ||
150 | |||
151 | create index django_admin_log_content_type_id_c4bce8eb | ||
152 | on django_admin_log (content_type_id); | ||
153 | |||
154 | create index django_admin_log_user_id_c564eba6 | ||
155 | on django_admin_log (user_id); | ||
156 | |||
157 | create unique index django_content_type_app_label_model_76bd3d3b_uniq | ||
158 | on django_content_type (app_label, model) | ||
159 | where [app_label] IS NOT NULL AND [model] IS NOT NULL; | ||
160 | |||
161 | create table django_migrations | ||
162 | ( | ||
163 | id int identity | ||
164 | primary key, | ||
165 | app nvarchar(255) not null, | ||
166 | name nvarchar(255) not null, | ||
167 | applied datetime2 not null | ||
168 | ); | ||
169 | |||
170 | create table django_session | ||
171 | ( | ||
172 | session_key nvarchar(40) not null | ||
173 | primary key, | ||
174 | session_data nvarchar(max) not null, | ||
175 | expire_date datetime2 not null | ||
176 | ); | ||
177 | |||
178 | create index django_session_expire_date_a5c62663 | ||
179 | on django_session (expire_date); | ||
180 | |||
181 | create table oauth2_provider_application | ||
182 | ( | ||
183 | id bigint identity | ||
184 | primary key, | ||
185 | client_id nvarchar(100) not null | ||
186 | unique, | ||
187 | redirect_uris nvarchar(max) not null, | ||
188 | client_type nvarchar(32) not null, | ||
189 | authorization_grant_type nvarchar(32) not null, | ||
190 | client_secret nvarchar(255) not null, | ||
191 | name nvarchar(255) not null, | ||
192 | user_id int | ||
193 | constraint oauth2_provider_application_user_id_79829054_fk_auth_user_id | ||
194 | references auth_user, | ||
195 | skip_authorization bit not null, | ||
196 | created datetime2 not null, | ||
197 | updated datetime2 not null | ||
198 | ); | ||
199 | |||
200 | create table oauth2_provider_accesstoken | ||
201 | ( | ||
202 | id bigint identity | ||
203 | primary key, | ||
204 | token nvarchar(255) not null | ||
205 | unique, | ||
206 | expires datetime2 not null, | ||
207 | scope nvarchar(max) not null, | ||
208 | application_id bigint | ||
209 | constraint oauth2_provider_accesstoken_application_id_b22886e1_fk_oauth2_provider_application_id | ||
210 | references oauth2_provider_application, | ||
211 | user_id int | ||
212 | constraint oauth2_provider_accesstoken_user_id_6e4c9a65_fk_auth_user_id | ||
213 | references auth_user, | ||
214 | created datetime2 not null, | ||
215 | updated datetime2 not null, | ||
216 | source_refresh_token_id bigint | ||
217 | ); | ||
218 | |||
219 | create index oauth2_provider_accesstoken_user_id_6e4c9a65 | ||
220 | on oauth2_provider_accesstoken (user_id); | ||
221 | |||
222 | create index oauth2_provider_accesstoken_application_id_b22886e1 | ||
223 | on oauth2_provider_accesstoken (application_id); | ||
224 | |||
225 | create unique index oauth2_provider_accesstoken_source_refresh_token_id_e66fbc72_uniq | ||
226 | on oauth2_provider_accesstoken (source_refresh_token_id) | ||
227 | where [source_refresh_token_id] IS NOT NULL; | ||
228 | |||
229 | create index oauth2_provider_application_client_secret_53133678 | ||
230 | on oauth2_provider_application (client_secret); | ||
231 | |||
232 | create index oauth2_provider_application_user_id_79829054 | ||
233 | on oauth2_provider_application (user_id); | ||
234 | |||
235 | create table oauth2_provider_grant | ||
236 | ( | ||
237 | id bigint identity | ||
238 | primary key, | ||
239 | code nvarchar(255) not null | ||
240 | unique, | ||
241 | expires datetime2 not null, | ||
242 | redirect_uri nvarchar(255) not null, | ||
243 | scope nvarchar(max) not null, | ||
244 | application_id bigint not null | ||
245 | constraint oauth2_provider_grant_application_id_81923564_fk_oauth2_provider_application_id | ||
246 | references oauth2_provider_application, | ||
247 | user_id int not null | ||
248 | constraint oauth2_provider_grant_user_id_e8f62af8_fk_auth_user_id | ||
249 | references auth_user, | ||
250 | created datetime2 not null, | ||
251 | updated datetime2 not null, | ||
252 | code_challenge nvarchar(128) not null, | ||
253 | code_challenge_method nvarchar(10) not null | ||
254 | ); | ||
255 | |||
256 | create index oauth2_provider_grant_user_id_e8f62af8 | ||
257 | on oauth2_provider_grant (user_id); | ||
258 | |||
259 | create index oauth2_provider_grant_application_id_81923564 | ||
260 | on oauth2_provider_grant (application_id); | ||
261 | """ | ||
262 | |||
263 | hil_sql_2 = """ | ||
264 | create table oauth2_provider_refreshtoken | ||
265 | ( | ||
266 | id bigint identity | ||
267 | primary key, | ||
268 | token nvarchar(255) not null, | ||
269 | access_token_id bigint | ||
270 | constraint oauth2_provider_refreshtoken_access_token_id_775e84e8_fk_oauth2_provider_accesstoken_id | ||
271 | references oauth2_provider_accesstoken, | ||
272 | application_id bigint not null | ||
273 | constraint oauth2_provider_refreshtoken_application_id_2d1c311b_fk_oauth2_provider_application_id | ||
274 | references oauth2_provider_application, | ||
275 | user_id int not null | ||
276 | constraint oauth2_provider_refreshtoken_user_id_da837fce_fk_auth_user_id | ||
277 | references auth_user, | ||
278 | created datetime2 not null, | ||
279 | updated datetime2 not null, | ||
280 | revoked datetime2 | ||
281 | ); | ||
282 | |||
283 | alter table oauth2_provider_accesstoken | ||
284 | add constraint oauth2_provider_accesstoken_source_refresh_token_id_e66fbc72_fk_oauth2_provider_refreshtoken_id | ||
285 | foreign key (source_refresh_token_id) references oauth2_provider_refreshtoken; | ||
286 | |||
287 | create unique index oauth2_provider_refreshtoken_token_revoked_af8a5134_uniq | ||
288 | on oauth2_provider_refreshtoken (token, revoked) | ||
289 | where [token] IS NOT NULL AND [revoked] IS NOT NULL; | ||
290 | |||
291 | create index oauth2_provider_refreshtoken_user_id_da837fce | ||
292 | on oauth2_provider_refreshtoken (user_id); | ||
293 | |||
294 | create unique index oauth2_provider_refreshtoken_access_token_id_775e84e8_uniq | ||
295 | on oauth2_provider_refreshtoken (access_token_id) | ||
296 | where [access_token_id] IS NOT NULL; | ||
297 | |||
298 | create index oauth2_provider_refreshtoken_application_id_2d1c311b | ||
299 | on oauth2_provider_refreshtoken (application_id); | ||
300 | |||
301 | create table hil_doc | ||
302 | ( | ||
303 | id int identity | ||
304 | primary key, | ||
305 | metadata_version_id nvarchar(64) not null, | ||
306 | application_id nvarchar(64) not null, | ||
307 | status tinyint default 0 not null, | ||
308 | main_applicant nvarchar(16) not null, | ||
309 | co_applicant nvarchar(16) not null, | ||
310 | guarantor_1 nvarchar(16) not null, | ||
311 | guarantor_2 nvarchar(16) not null, | ||
312 | document_name nvarchar(255) not null, | ||
313 | document_scheme nvarchar(64) not null, | ||
314 | data_source nvarchar(64) not null, | ||
315 | upload_finish_time datetime, | ||
316 | update_time datetime not null, | ||
317 | create_time datetime not null | ||
318 | ); | ||
319 | |||
320 | create index hil_doc_upload_finish_time_index | ||
321 | on hil_doc (upload_finish_time); | ||
322 | |||
323 | create index hil_doc_create_time_index | ||
324 | on hil_doc (create_time); | ||
325 | |||
326 | create index hil_doc_application_id_status_index | ||
327 | on hil_doc (application_id, status); | ||
328 | |||
329 | create table upload_doc_records | ||
330 | ( | ||
331 | id int identity | ||
332 | primary key, | ||
333 | metadata_version_id nvarchar(64) not null, | ||
334 | application_id nvarchar(64) not null, | ||
335 | main_applicant nvarchar(16) not null, | ||
336 | co_applicant nvarchar(16) not null, | ||
337 | guarantor_1 nvarchar(16) not null, | ||
338 | guarantor_2 nvarchar(16) not null, | ||
339 | document_name nvarchar(255) not null, | ||
340 | document_scheme nvarchar(64) not null, | ||
341 | business_type nvarchar(64) not null, | ||
342 | data_source nvarchar(64) not null, | ||
343 | upload_finish_time datetime, | ||
344 | update_time datetime not null, | ||
345 | create_time datetime not null | ||
346 | ); | ||
347 | |||
348 | create unique index upload_doc_records_metadata_version_id_uindex | ||
349 | on upload_doc_records (metadata_version_id); | ||
350 | """ | ||
351 | |||
352 | afc_sql = """ | ||
353 | create table keywords | ||
354 | ( | ||
355 | id int identity primary key, | ||
356 | keyword nvarchar(64) not null, | ||
357 | type tinyint default 0 not null, | ||
358 | on_off bit default 1 not null, | ||
359 | update_time datetime not null, | ||
360 | create_time datetime not null | ||
361 | ); | ||
362 | |||
363 | create table priority_application | ||
364 | ( | ||
365 | id int identity | ||
366 | primary key, | ||
367 | application_id nvarchar(64) not null, | ||
368 | on_off bit default 1 not null, | ||
369 | update_time datetime not null, | ||
370 | create_time datetime not null | ||
371 | ); | ||
372 | |||
373 | create index priority_application_application_id_on_off_index | ||
374 | on priority_application (application_id, on_off); | ||
375 | |||
376 | create table gcap_records | ||
377 | ( | ||
378 | id int identity primary key, | ||
379 | status int, | ||
380 | rating int, | ||
381 | entity nvarchar(128), | ||
382 | application_id nvarchar(64) not null, | ||
383 | application_version int, | ||
384 | intermediate_decision nvarchar(128), | ||
385 | submit_datetime datetime, | ||
386 | update_time datetime not null, | ||
387 | create_time datetime not null | ||
388 | ); | ||
389 | |||
390 | create table afc_doc | ||
391 | ( | ||
392 | id int identity | ||
393 | primary key, | ||
394 | metadata_version_id nvarchar(64) not null, | ||
395 | application_id nvarchar(64) not null, | ||
396 | status tinyint default 0 not null, | ||
397 | main_applicant nvarchar(16) not null, | ||
398 | co_applicant nvarchar(16) not null, | ||
399 | guarantor_1 nvarchar(16) not null, | ||
400 | guarantor_2 nvarchar(16) not null, | ||
401 | document_name nvarchar(255) not null, | ||
402 | document_scheme nvarchar(64) not null, | ||
403 | data_source nvarchar(64) not null, | ||
404 | upload_finish_time datetime, | ||
405 | update_time datetime not null, | ||
406 | create_time datetime not null | ||
407 | ); | ||
408 | |||
409 | create index afc_doc_upload_finish_time_index | ||
410 | on afc_doc (upload_finish_time); | ||
411 | |||
412 | create index afc_doc_create_time_index | ||
413 | on afc_doc (create_time); | ||
414 | |||
415 | create index afc_doc_application_id_status_index | ||
416 | on afc_doc (application_id, status); | ||
417 | """ | ||
418 | |||
419 | hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=47.97.220.40;DATABASE=hil;UID=SA;PWD=19951019Mssql', autocommit=True) | ||
420 | |||
421 | hil_cursor = hil_cnxn.cursor() | ||
422 | hil_cursor.execute(hil_sql_1) | ||
423 | hil_cursor.execute(hil_sql_2) | ||
424 | |||
425 | hil_cursor.close() | ||
426 | hil_cnxn.close() | ||
427 | |||
428 | afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=47.97.220.40;DATABASE=afc;UID=SA;PWD=19951019Mssql', autocommit=True) | ||
429 | |||
430 | afc_cursor = afc_cnxn.cursor() | ||
431 | afc_cursor.execute(afc_sql) | ||
432 | |||
433 | afc_cursor.close() | ||
434 | afc_cnxn.close() |
... | @@ -95,8 +95,15 @@ DATABASES = { | ... | @@ -95,8 +95,15 @@ DATABASES = { |
95 | 'default': conf.get_namespace('MYSQL_DEFAULT_'), | 95 | 'default': conf.get_namespace('MYSQL_DEFAULT_'), |
96 | 'afc': conf.get_namespace('MYSQL_AFC_') | 96 | 'afc': conf.get_namespace('MYSQL_AFC_') |
97 | } | 97 | } |
98 | |||
99 | for db_setting in DATABASES.values(): | ||
100 | db_setting['OPTIONS'] = { | ||
101 | 'driver': 'ODBC Driver 17 for SQL Server' | ||
102 | } | ||
103 | |||
104 | |||
98 | DATABASE_ROUTERS = ['settings.database.DBRouter'] | 105 | DATABASE_ROUTERS = ['settings.database.DBRouter'] |
99 | MYSQLPOOL_ARGUMENTS = database.MYSQLPOOL_ARGUMENTS | 106 | # MYSQLPOOL_ARGUMENTS = database.MYSQLPOOL_ARGUMENTS |
100 | 107 | ||
101 | 108 | ||
102 | # Password validation | 109 | # Password validation |
... | @@ -180,3 +187,5 @@ OAUTH2_PROVIDER = { | ... | @@ -180,3 +187,5 @@ OAUTH2_PROVIDER = { |
180 | # this is the list of available scopes | 187 | # this is the list of available scopes |
181 | 'SCOPES': {'read': 'Read scope', 'write': 'Write scope'} | 188 | 'SCOPES': {'read': 'Read scope', 'write': 'Write scope'} |
182 | } | 189 | } |
190 | |||
191 | # print(DATABASES) | ... | ... |
... | @@ -2,10 +2,10 @@ | ... | @@ -2,10 +2,10 @@ |
2 | Database | 2 | Database |
3 | https://docs.djangoproject.com/en/1.11/ref/settings/#databases | 3 | https://docs.djangoproject.com/en/1.11/ref/settings/#databases |
4 | """ | 4 | """ |
5 | import pymysql | 5 | # import pymysql |
6 | from django.db.models import options | 6 | from django.db.models import options |
7 | 7 | ||
8 | pymysql.install_as_MySQLdb() | 8 | # pymysql.install_as_MySQLdb() |
9 | 9 | ||
10 | # 同一App下的Model可能会存储到不同的db,所以根据app_label来做db_router不是特别合适 | 10 | # 同一App下的Model可能会存储到不同的db,所以根据app_label来做db_router不是特别合适 |
11 | # 所以添加situ_db_label来映射model到db | 11 | # 所以添加situ_db_label来映射model到db |
... | @@ -13,13 +13,13 @@ pymysql.install_as_MySQLdb() | ... | @@ -13,13 +13,13 @@ pymysql.install_as_MySQLdb() |
13 | options.DEFAULT_NAMES = tuple(list(options.DEFAULT_NAMES) + ['situ_db_label']) | 13 | options.DEFAULT_NAMES = tuple(list(options.DEFAULT_NAMES) + ['situ_db_label']) |
14 | 14 | ||
15 | # 数据库连接池配置 | 15 | # 数据库连接池配置 |
16 | MYSQLPOOL_ARGUMENTS = { | 16 | # MYSQLPOOL_ARGUMENTS = { |
17 | 'recycle': 30, | 17 | # 'recycle': 30, |
18 | 'pool_size': 64, | 18 | # 'pool_size': 64, |
19 | 'max_overflow': 10, | 19 | # 'max_overflow': 10, |
20 | 'timeout': 5, | 20 | # 'timeout': 5, |
21 | 'use_threadlocal': False, | 21 | # 'use_threadlocal': False, |
22 | } | 22 | # } |
23 | 23 | ||
24 | 24 | ||
25 | class DBRouter(object): | 25 | class DBRouter(object): | ... | ... |
-
Please register or sign in to post a comment