-
Notifications
You must be signed in to change notification settings - Fork 877
/
databaseDialog.ts
1940 lines (1782 loc) · 88.9 KB
/
databaseDialog.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
import { DefaultInputWidth, DefaultTableWidth, DefaultMinTableRowCount, DefaultMaxTableRowCount, getTableHeight, DialogButton } from '../../ui/dialogBase';
import { IObjectManagementService } from 'mssql';
import * as localizedConstants from '../localizedConstants';
import { CreateDatabaseDocUrl, DatabaseGeneralPropertiesDocUrl, DatabaseFilesPropertiesDocUrl, DatabaseOptionsPropertiesDocUrl, DatabaseScopedConfigurationPropertiesDocUrl, DatabaseFileGroupsPropertiesDocUrl, QueryStorePropertiesDocUrl } from '../constants';
import { Database, DatabaseFile, DatabaseScopedConfigurationsInfo, DatabaseViewInfo, FileGrowthType, FileGroup, FileGroupType } from '../interfaces';
import { convertNumToTwoDecimalStringInMB } from '../utils';
import { isUndefinedOrNull } from '../../types';
import { DatabaseFileDialog } from './databaseFileDialog';
import * as vscode from 'vscode';
const MAXDOP_Max_Limit = 32767;
const PAUSED_RESUMABLE_INDEX_Max_Limit = 71582;
const DscTableRowLength = 15;
export class DatabaseDialog extends ObjectManagementDialogBase<Database, DatabaseViewInfo> {
// Database Properties tabs
private generalTab: azdata.Tab;
private filesTab: azdata.Tab;
private optionsTab: azdata.Tab;
private fileGroupsTab: azdata.Tab;
private dscTab: azdata.Tab;
private queryStoreTab: azdata.Tab;
private optionsTabSectionsContainer: azdata.Component[] = [];
private activeTabId: string;
// Database properties options
// General Tab
private readonly generalTabId: string = 'generalDatabaseId';
private nameInput: azdata.InputBoxComponent;
private backupSection: azdata.GroupContainer;
private lastDatabaseBackupInput: azdata.InputBoxComponent;
private lastDatabaseLogBackupInput: azdata.InputBoxComponent;
private databaseSection: azdata.GroupContainer;
private statusInput: azdata.InputBoxComponent;
private ownerInput: azdata.InputBoxComponent;
private dateCreatedInput: azdata.InputBoxComponent;
private sizeInput: azdata.InputBoxComponent;
private spaceAvailabeInput: azdata.InputBoxComponent;
private numberOfUsersInput: azdata.InputBoxComponent;
private memoryAllocatedInput: azdata.InputBoxComponent;
private memoryUsedInput: azdata.InputBoxComponent;
private collationInput: azdata.InputBoxComponent;
// Files Tab
private readonly filesTabId: string = 'filesDatabaseId';
private databaseFilesTable: azdata.TableComponent;
private rowDatafileGroupsOptions: string[];
private filestreamDatafileGroupsOptions: string[];
// fileGroups Tab
private readonly fileGroupsTabId: string = 'fileGroupsDatabaseId';
private rowsFilegroupsTable: azdata.TableComponent;
private filestreamFilegroupsTable: azdata.TableComponent;
private memoryOptimizedFilegroupsTable: azdata.TableComponent;
private rowsFilegroupNameInput: azdata.InputBoxComponent;
private filestreamFilegroupNameInput: azdata.InputBoxComponent;
private memoryOptimizedFilegroupNameInput: azdata.InputBoxComponent;
private newFileGroupTemporaryId: number = 0;
private rowDataFileGroupsTableRows: FileGroup[] = [];
private filestreamDataFileGroupsTableRows: FileGroup[] = [];
private memoryoptimizedFileGroupsTableRows: FileGroup[] = [];
// Options Tab
private readonly optionsTabId: string = 'optionsDatabaseId';
private autoCreateIncrementalStatisticsInput: azdata.CheckBoxComponent;
private autoCreateStatisticsInput: azdata.CheckBoxComponent;
private autoShrinkInput: azdata.CheckBoxComponent;
private autoUpdateStatisticsInput: azdata.CheckBoxComponent;
private autoUpdateStatisticsAsynchronouslyInput: azdata.CheckBoxComponent;
private isLedgerDatabaseInput!: azdata.CheckBoxComponent;
private pageVerifyInput!: azdata.DropDownComponent;
private targetRecoveryTimeInSecInput!: azdata.InputBoxComponent;
private databaseReadOnlyInput!: azdata.CheckBoxComponent;
private encryptionEnabledInput: azdata.CheckBoxComponent;
private restrictAccessInput!: azdata.DropDownComponent;
// Database Scoped Configurations Tab
private readonly dscTabId: string = 'dscDatabaseId';
private dscTabSectionsContainer: azdata.Component[] = [];
private dscTable: azdata.TableComponent;
private currentRowId: number;
private valueForPrimaryDropdown: azdata.DropDownComponent;
private valueForSecondaryDropdown: azdata.DropDownComponent;
private setSecondaryCheckboxForDropdowns: azdata.CheckBoxComponent;
private valueForPrimaryInput: azdata.InputBoxComponent;
private valueForSecondaryInput: azdata.InputBoxComponent;
private setSecondaryCheckboxForInputType: azdata.CheckBoxComponent;
private dscPrimaryValueDropdownGroup: azdata.GroupContainer;
private dscSecondaryValueDropdownGroup: azdata.GroupContainer;
private dscSecondaryCheckboxForDropdownGroup: azdata.GroupContainer;
private dscPrimaryValueInputGroup: azdata.GroupContainer;
private dscSecondaryValueInputGroup: azdata.GroupContainer;
private dscSecondaryCheckboxForInputGroup: azdata.GroupContainer;
private setFocusToInput: azdata.InputBoxComponent = undefined;
private currentRowObjectInfo: DatabaseScopedConfigurationsInfo;
// Query store Tab
private readonly queryStoreTabId: string = 'queryStoreTabId';
private queryStoreTabSectionsContainer: azdata.Component[] = [];
private areQueryStoreOptionsEnabled: boolean;
private requestedOperationMode: azdata.DropDownComponent;
private dataFlushIntervalInMinutes: azdata.InputBoxComponent;
private statisticsCollectionInterval: azdata.DropDownComponent;
private maxPlansPerQuery: azdata.InputBoxComponent;
private maxSizeinMB: azdata.InputBoxComponent;
private queryStoreCaptureMode: azdata.DropDownComponent;
private sizeBasedCleanupMode: azdata.DropDownComponent;
private stateQueryThresholdInDays: azdata.InputBoxComponent;
private waitStatisticsCaptureMode: azdata.DropDownComponent;
private executionCount: azdata.InputBoxComponent;
private staleThreshold: azdata.DropDownComponent;
private totalCompileCPUTimeInMS: azdata.InputBoxComponent;
private totalExecutionCPUTimeInMS: azdata.InputBoxComponent;
private operationModeOffOption: string;
private purgeQueryDataButton: azdata.ButtonComponent;
constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) {
super(objectManagementService, options);
}
protected override get helpUrl(): string {
return this.options.isNewObject ? CreateDatabaseDocUrl : this.getDatabasePropertiesDocUrl();
}
private getDatabasePropertiesDocUrl(): string {
let helpUrl = '';
switch (this.activeTabId) {
case this.generalTabId:
helpUrl = DatabaseGeneralPropertiesDocUrl;
break;
case this.filesTabId:
helpUrl = DatabaseFilesPropertiesDocUrl;
break;
case this.fileGroupsTabId:
helpUrl = DatabaseFileGroupsPropertiesDocUrl;
break;
case this.optionsTabId:
helpUrl = DatabaseOptionsPropertiesDocUrl;
break;
case this.dscTabId:
helpUrl = DatabaseScopedConfigurationPropertiesDocUrl;
break;
case this.queryStoreTabId:
helpUrl = QueryStorePropertiesDocUrl;
break;
default:
break;
}
return helpUrl;
}
protected async initializeUI(): Promise<void> {
if (this.options.isNewObject) {
let components = [];
components.push(this.initializeGeneralSection());
components.push(this.initializeOptionsSection());
if (this.viewInfo.isAzureDB) {
components.push(this.initializeConfigureSLOSection());
}
this.formContainer.addItems(components);
} else {
// Initialize general Tab sections
this.initializeBackupSection();
this.initializeDatabaseSection();
//Initialize options Tab sections
this.initializeOptionsGeneralSection();
this.initializeAutomaticSection();
if (!isUndefinedOrNull(this.objectInfo.isLedgerDatabase)) {
this.initializeLedgerSection();
}
if (!isUndefinedOrNull(this.objectInfo.pageVerify) && !isUndefinedOrNull(this.objectInfo.targetRecoveryTimeInSec)) {
this.initializeRecoverySection();
}
this.initializeStateSection();
const tabs: azdata.Tab[] = [];
// Initialize general Tab
this.generalTab = {
title: localizedConstants.GeneralSectionHeader,
id: this.generalTabId,
content: this.createGroup('', [
this.databaseSection,
this.backupSection
], false)
};
tabs.push(this.generalTab);
// Prepare the copies of individual filegroups tables data and filegroups options for files tab
if (!isUndefinedOrNull(this.objectInfo.filegroups)) {
this.updateFileGroupsOptionsAndTableRows();
}
// Initialize Files Tab
// Files tab is only enabled for SQL Server properties view
if (!isUndefinedOrNull(this.objectInfo.isFilesTabSupported)) {
const filesGeneralSection = this.initializeFilesGeneralSection();
const databaseFilesSection = this.initializeDatabaseFilesSection();
this.filesTab = {
title: localizedConstants.FilesSectionHeader,
id: this.filesTabId,
content: this.createGroup('', [filesGeneralSection, databaseFilesSection], false)
};
tabs.push(this.filesTab);
}
// Initilaize FileGroups Tab
if (!isUndefinedOrNull(this.objectInfo.filegroups)) {
const rowsFileGroupSection = await this.initializeRowsFileGroupSection();
const fileStreamFileGroupSection = this.initializeFileStreamFileGroupSection();
const memoryOptimizedFileGroupSection = this.initializeMemoryOptimizedFileGroupSection();
this.fileGroupsTab = {
title: localizedConstants.FileGroupsSectionHeader,
id: this.fileGroupsTabId,
content: this.createGroup('', [rowsFileGroupSection, fileStreamFileGroupSection, memoryOptimizedFileGroupSection], false)
};
tabs.push(this.fileGroupsTab);
}
// Initialize Options Tab
this.optionsTab = {
title: localizedConstants.OptionsSectionHeader,
id: this.optionsTabId,
content: this.createGroup('', this.optionsTabSectionsContainer, false)
};
tabs.push(this.optionsTab);
// Initialize DSC Tab section
if (!isUndefinedOrNull(this.objectInfo.databaseScopedConfigurations)) {
await this.initializeDatabaseScopedConfigurationSection();
this.dscTabSectionsContainer.push(await this.initializeDscValueDropdownTypeSection())
this.dscTabSectionsContainer.push(await this.initializeDscValueInputTypeSection())
this.dscTab = {
title: localizedConstants.DatabaseScopedConfigurationTabHeader,
id: this.dscTabId,
content: this.createGroup('', this.dscTabSectionsContainer, false)
}
tabs.push(this.dscTab);
}
// Intialize Query Store Tab
if (!isUndefinedOrNull(this.objectInfo.queryStoreOptions)) {
this.initializeQueryStoreGeneralSection();
this.initializeQueryStoreMonitoringSection();
this.initializeQueryStoreRetentionSection();
if (!isUndefinedOrNull(this.objectInfo.queryStoreOptions.capturePolicyOptions)) {
this.initializeQueryStoreCapturePolicySection();
}
await this.initializeQueryStoreCurrentDiskStorageSection();
this.queryStoreTab = {
title: localizedConstants.QueryStoreTabHeader,
id: this.queryStoreTabId,
content: this.createGroup('', this.queryStoreTabSectionsContainer, false)
}
tabs.push(this.queryStoreTab);
}
// Initialize tab group with tabbed panel
const propertiesTabGroup = { title: '', tabs: tabs };
const propertiesTabbedPannel = this.modelView.modelBuilder.tabbedPanel()
.withTabs([propertiesTabGroup])
.withProps({
CSSStyles: {
'margin': '-10px 0px 0px -10px'
}
})
.component();
this.disposables.push(
propertiesTabbedPannel.onTabChanged(async tabId => {
this.activeTabId = tabId;
}));
this.formContainer.addItem(propertiesTabbedPannel);
}
}
protected override async validateInput(): Promise<string[]> {
let errors = await super.validateInput();
let collationNames = this.viewInfo.collationNames?.options;
if (collationNames?.length > 0 && !collationNames.some(name => name.toLowerCase() === this.objectInfo.collationName?.toLowerCase())) {
errors.push(localizedConstants.CollationNotValidError(this.objectInfo.collationName ?? ''));
}
// Validate Rows Filegroup names
if (this.objectInfo.filegroups?.length > 0) {
let seenFilegroups = new Set<string>;
this.objectInfo.filegroups.map(function (item) {
if (item.name === '') {
errors.push(localizedConstants.EmptyFilegroupNameError);
} else if (seenFilegroups.has(item.name)) {
errors.push(localizedConstants.FilegroupExistsError(item.name));
} else {
seenFilegroups.add(item.name)
}
});
}
return errors;
}
//#region Create Database
private initializeGeneralSection(): azdata.GroupContainer {
let containers: azdata.Component[] = [];
// The max length for database names is 128 characters: https://learn.microsoft.com/sql/t-sql/functions/db-name-transact-sql
const maxLengthDatabaseName: number = 128;
const props: azdata.InputBoxProperties = {
ariaLabel: localizedConstants.NameText,
required: true,
maxLength: maxLengthDatabaseName
};
this.nameInput = this.createInputBox(async () => {
this.objectInfo.name = this.nameInput.value;
}, props);
containers.push(this.createLabelInputContainer(localizedConstants.NameText, this.nameInput));
let loginNames = this.viewInfo.loginNames?.options;
if (loginNames?.length > 0) {
let defaultIndex = this.viewInfo.loginNames.defaultValueIndex;
this.objectInfo.owner = loginNames[defaultIndex];
let ownerDropbox = this.createDropdown(localizedConstants.OwnerText, async () => {
this.objectInfo.owner = ownerDropbox.value as string;
}, loginNames, loginNames[defaultIndex]);
containers.push(this.createLabelInputContainer(localizedConstants.OwnerText, ownerDropbox));
}
return this.createGroup(localizedConstants.GeneralSectionHeader, containers, false);
}
private initializeOptionsSection(): azdata.GroupContainer {
let containers: azdata.Component[] = [];
let collationNames = this.viewInfo.collationNames?.options;
if (collationNames?.length > 0) {
let defaultIndex = this.viewInfo.collationNames.defaultValueIndex;
this.objectInfo.collationName = collationNames[defaultIndex];
let collationDropbox = this.createDropdown(localizedConstants.CollationText, async () => {
this.objectInfo.collationName = collationDropbox.value as string;
}, collationNames, collationNames[defaultIndex], true, DefaultInputWidth, true, true);
containers.push(this.createLabelInputContainer(localizedConstants.CollationText, collationDropbox));
}
let recoveryModels = this.viewInfo.recoveryModels?.options;
if (recoveryModels?.length > 0) {
let defaultIndex = this.viewInfo.recoveryModels.defaultValueIndex;
this.objectInfo.recoveryModel = recoveryModels[defaultIndex];
let recoveryDropbox = this.createDropdown(localizedConstants.RecoveryModelText, async () => {
this.objectInfo.recoveryModel = recoveryDropbox.value as string;
}, recoveryModels, recoveryModels[defaultIndex]);
containers.push(this.createLabelInputContainer(localizedConstants.RecoveryModelText, recoveryDropbox));
}
let compatibilityLevels = this.viewInfo.compatibilityLevels?.options;
if (compatibilityLevels?.length > 0) {
let defaultIndex = this.viewInfo.compatibilityLevels.defaultValueIndex;
this.objectInfo.compatibilityLevel = compatibilityLevels[defaultIndex];
let compatibilityDropbox = this.createDropdown(localizedConstants.CompatibilityLevelText, async () => {
this.objectInfo.compatibilityLevel = compatibilityDropbox.value as string;
}, compatibilityLevels, compatibilityLevels[defaultIndex]);
containers.push(this.createLabelInputContainer(localizedConstants.CompatibilityLevelText, compatibilityDropbox));
}
let containmentTypes = this.viewInfo.containmentTypes?.options;
if (containmentTypes?.length > 0) {
let defaultIndex = this.viewInfo.containmentTypes.defaultValueIndex;
this.objectInfo.containmentType = containmentTypes[defaultIndex];
let containmentDropbox = this.createDropdown(localizedConstants.ContainmentTypeText, async () => {
this.objectInfo.containmentType = containmentDropbox.value as string;
}, containmentTypes, containmentTypes[defaultIndex]);
containers.push(this.createLabelInputContainer(localizedConstants.ContainmentTypeText, containmentDropbox));
}
return this.createGroup(localizedConstants.OptionsSectionHeader, containers, true, true);
}
//#endregion
//#region Database Properties - General Tab
private initializeBackupSection(): void {
// Last Database Backup
this.lastDatabaseBackupInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.LastDatabaseBackupText,
inputType: 'text',
enabled: this.options.isNewObject,
value: this.objectInfo.lastDatabaseBackup
});
const lastDatabaseBackupContainer = this.createLabelInputContainer(localizedConstants.LastDatabaseBackupText, this.lastDatabaseBackupInput);
// Last Database Log Backup
this.lastDatabaseLogBackupInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.LastDatabaseLogBackupText,
inputType: 'text',
enabled: this.options.isNewObject,
value: this.objectInfo.lastDatabaseLogBackup
});
const lastDatabaseLogBackupContainer = this.createLabelInputContainer(localizedConstants.LastDatabaseLogBackupText, this.lastDatabaseLogBackupInput);
this.backupSection = this.createGroup(localizedConstants.BackupSectionHeader, [
lastDatabaseBackupContainer,
lastDatabaseLogBackupContainer
], true);
}
private initializeDatabaseSection(): void {
// Database Name
this.nameInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.NamePropertyText,
inputType: 'text',
enabled: this.options.isNewObject,
value: this.objectInfo.name
});
const nameContainer = this.createLabelInputContainer(localizedConstants.NamePropertyText, this.nameInput);
// Database Status
this.statusInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.StatusText,
inputType: 'text',
enabled: this.options.isNewObject,
value: this.objectInfo.status
});
const statusContainer = this.createLabelInputContainer(localizedConstants.StatusText, this.statusInput);
// Database Owner
this.ownerInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.OwnerPropertyText,
inputType: 'text',
enabled: this.options.isNewObject,
value: this.objectInfo.owner
});
const ownerContainer = this.createLabelInputContainer(localizedConstants.OwnerPropertyText, this.ownerInput);
// Created Date
this.dateCreatedInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.DateCreatedText,
inputType: 'text',
enabled: this.options.isNewObject,
value: this.objectInfo.dateCreated
});
const dateCreatedContainer = this.createLabelInputContainer(localizedConstants.DateCreatedText, this.dateCreatedInput);
// Size
this.sizeInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.SizeText,
inputType: 'text',
enabled: this.options.isNewObject,
value: convertNumToTwoDecimalStringInMB(this.objectInfo.sizeInMb)
});
const sizeContainer = this.createLabelInputContainer(localizedConstants.SizeText, this.sizeInput);
// Space Available
this.spaceAvailabeInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.SpaceAvailableText,
inputType: 'text',
enabled: this.options.isNewObject,
value: convertNumToTwoDecimalStringInMB(this.objectInfo.spaceAvailableInMb)
});
const spaceAvailabeContainer = this.createLabelInputContainer(localizedConstants.SpaceAvailableText, this.spaceAvailabeInput);
// Number of Users
this.numberOfUsersInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.NumberOfUsersText,
inputType: 'text',
enabled: this.options.isNewObject,
value: this.objectInfo.numberOfUsers.toString()
});
const numberOfUsersContainer = this.createLabelInputContainer(localizedConstants.NumberOfUsersText, this.numberOfUsersInput);
// Memory Allocated To Memory Optimized Objects
this.memoryAllocatedInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.MemoryAllocatedText,
inputType: 'text',
enabled: this.options.isNewObject,
value: convertNumToTwoDecimalStringInMB(this.objectInfo.memoryAllocatedToMemoryOptimizedObjectsInMb)
});
const memoryAllocatedContainer = this.createLabelInputContainer(localizedConstants.MemoryAllocatedText, this.memoryAllocatedInput);
// Memory Used By Memory Optimized Objects
this.memoryUsedInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.MemoryUsedText,
inputType: 'text',
enabled: this.options.isNewObject,
value: convertNumToTwoDecimalStringInMB(this.objectInfo.memoryUsedByMemoryOptimizedObjectsInMb)
});
const memoryUsedContainer = this.createLabelInputContainer(localizedConstants.MemoryUsedText, this.memoryUsedInput);
// Collation
this.collationInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.CollationText,
inputType: 'text',
enabled: this.options.isNewObject,
value: this.objectInfo.collationName
});
const collationContainer = this.createLabelInputContainer(localizedConstants.CollationText, this.collationInput);
this.databaseSection = this.createGroup(localizedConstants.DatabaseSectionHeader, [
nameContainer,
statusContainer,
ownerContainer,
collationContainer,
dateCreatedContainer,
sizeContainer,
spaceAvailabeContainer,
numberOfUsersContainer,
memoryAllocatedContainer,
memoryUsedContainer
], true);
}
//#endregion
//#region Database Properties - Files Tab
private initializeFilesGeneralSection(): azdata.GroupContainer {
let containers: azdata.Component[] = [];
// Database name
this.nameInput = this.createInputBox(async () => { }, {
ariaLabel: localizedConstants.DatabaseNameText,
inputType: 'text',
enabled: this.options.isNewObject,
value: this.objectInfo.name
});
containers.push(this.createLabelInputContainer(localizedConstants.DatabaseNameText, this.nameInput));
// Owner
let loginNames = this.viewInfo.loginNames?.options;
if (loginNames?.length > 0) {
// Removing <default> login name from the list and adding current owner if not exists
if (!this.viewInfo.loginNames?.options.find(owner => owner === this.objectInfo.owner)) {
loginNames[0] = this.objectInfo.owner;
} else {
loginNames.splice(0, 1);
}
let ownerDropbox = this.createDropdown(localizedConstants.OwnerText, async () => {
this.objectInfo.owner = ownerDropbox.value as string;
}, loginNames, this.objectInfo.owner);
containers.push(this.createLabelInputContainer(localizedConstants.OwnerText, ownerDropbox));
}
return this.createGroup('', containers, false);
}
private initializeDatabaseFilesSection(): azdata.GroupContainer {
this.databaseFilesTable = this.modelView.modelBuilder.table().withProps({
columns: [{
type: azdata.ColumnType.text,
value: localizedConstants.LogicalNameText
}, {
type: azdata.ColumnType.text,
value: localizedConstants.FileTypeText
}, {
type: azdata.ColumnType.text,
value: localizedConstants.FilegroupText
}, {
type: azdata.ColumnType.text,
value: localizedConstants.SizeInMbText
}, {
type: azdata.ColumnType.text,
value: localizedConstants.AutogrowthMaxsizeText
}, {
type: azdata.ColumnType.text,
value: localizedConstants.PathText
}, {
type: azdata.ColumnType.text,
value: localizedConstants.FileNameText
}],
data: this.objectInfo.files?.map(file => {
return this.convertToDataView(file);
}),
height: getTableHeight(this.objectInfo.files?.length, DefaultMinTableRowCount, DefaultMaxTableRowCount),
width: DefaultTableWidth,
forceFitColumns: azdata.ColumnSizingMode.DataFit,
CSSStyles: {
'margin-left': '10px'
}
}).component();
const addButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.AddButton,
buttonHandler: (button) => this.onAddDatabaseFilesButtonClicked(button)
};
const removeButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.RemoveButton,
buttonHandler: () => this.onRemoveDatabaseFilesButtonClicked()
};
const editbuttonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.EditButton,
buttonHandler: (button) => this.onEditDatabaseFilesButtonClicked(button)
};
const databaseFilesButtonContainer = this.addButtonsForTable(this.databaseFilesTable, addButtonComponent, removeButtonComponent, editbuttonComponent);
return this.createGroup(localizedConstants.DatabaseFilesText, [this.databaseFilesTable, databaseFilesButtonContainer], true);
}
/**
* Converts the file object to a data view object
* @param file database file object
* @returns data view object
*/
private convertToDataView(file: DatabaseFile): any[] {
return [
file.name,
file.type,
file.fileGroup,
file.sizeInMb,
file.isAutoGrowthEnabled ? localizedConstants.AutoGrowthValueStringGenerator(file.type !== localizedConstants.FilestreamFileType
, file.autoFileGrowth.toString()
, file.autoFileGrowthType === FileGrowthType.Percent
, file.maxSizeLimitInMb) : localizedConstants.NoneText,
file.path,
file.fileNameWithExtension
];
}
private async onAddDatabaseFilesButtonClicked(button: azdata.ButtonComponent): Promise<void> {
// Open file dialog to create file
const result = await this.openDatabaseFileDialog(button);
if (!isUndefinedOrNull(result)) {
this.objectInfo.files?.push(result);
var newData = this.objectInfo.files?.map(file => {
return this.convertToDataView(file);
});
await this.setTableData(this.databaseFilesTable, newData, DefaultMaxTableRowCount);
await this.updateFileGroupsTablesfileCount(result.type);
}
}
private async onEditDatabaseFilesButtonClicked(button: azdata.ButtonComponent): Promise<void> {
if (this.databaseFilesTable.selectedRows.length === 1) {
const result = await this.openDatabaseFileDialog(button);
if (!isUndefinedOrNull(result)) {
this.objectInfo.files[this.databaseFilesTable.selectedRows[0]] = result;
var newData = this.objectInfo.files?.map(file => {
return this.convertToDataView(file);
});
await this.setTableData(this.databaseFilesTable, newData, DefaultMaxTableRowCount);
await this.updateFileGroupsTablesfileCount(result.type);
}
}
}
/**
* Removes the selected database file from the table
*/
private async onRemoveDatabaseFilesButtonClicked(): Promise<void> {
if (this.databaseFilesTable.selectedRows.length === 1) {
await this.updateFileGroupsTablesfileCount(this.objectInfo.files[this.databaseFilesTable.selectedRows[0]].type);
this.objectInfo.files?.splice(this.databaseFilesTable.selectedRows[0], 1);
var newData = this.objectInfo.files?.map(file => {
return this.convertToDataView(file);
});
await this.setTableData(this.databaseFilesTable, newData, DefaultMaxTableRowCount);
}
}
/**
* Updating the filegroups tables number of files count for each action of adding/editing/removing a database file
* @param fileType type of the file to get the data for the table
*/
private async updateFileGroupsTablesfileCount(fileType: string): Promise<void> {
if (fileType === localizedConstants.RowsDataFileType) {
let data = this.getTableData(FileGroupType.RowsFileGroup);
await this.setTableData(this.rowsFilegroupsTable, data);
}
else if (fileType === localizedConstants.FilestreamFileType) {
let data = this.getTableData(FileGroupType.FileStreamDataFileGroup);
await this.setTableData(this.filestreamFilegroupsTable, data);
data = this.getTableData(FileGroupType.MemoryOptimizedDataFileGroup);
await this.setTableData(this.memoryOptimizedFilegroupsTable, data);
}
}
/**
* Validate the selected row to enable/disable the remove button
* @returns true if the remove button should be enabled, false otherwise
*/
protected override removeButtonEnabled(table: azdata.TableComponent): boolean {
let isEnabled = true;
if (table === this.databaseFilesTable && this.databaseFilesTable.selectedRows !== undefined) {
const selectedRowId = this.objectInfo.files[this.databaseFilesTable.selectedRows[0]].id;
// Cannot delete a Primary row data file, Id is always 1.
if (this.databaseFilesTable.selectedRows.length === 1 && selectedRowId === 1) {
isEnabled = false;
}
// Cannot remove a log file if there are no other log files, LogFiletype is always a Log file type
else if (this.objectInfo.files[this.databaseFilesTable.selectedRows[0]].type === localizedConstants.LogFiletype) {
isEnabled = false;
this.objectInfo.files.forEach(file => {
if (file.id !== selectedRowId && file.type === localizedConstants.LogFiletype) {
isEnabled = true;
}
});
}
}
else if (table === this.rowsFilegroupsTable && this.rowsFilegroupsTable.selectedRows !== undefined && this.rowsFilegroupsTable.selectedRows.length === 1) {
const selectedRow = this.rowDataFileGroupsTableRows[this.rowsFilegroupsTable.selectedRows[0]];
// Cannot delete a row file if the fileGroup is Primary.
if (selectedRow.name === 'PRIMARY' && selectedRow.id > 0) {
isEnabled = false;
}
}
return isEnabled;
}
private async openDatabaseFileDialog(button: azdata.ButtonComponent): Promise<DatabaseFile> {
const defaultFileSizeInMb: number = 8
const defaultFileGrowthInMb: number = 64
const defaultFileGrowthInPercent: number = 10;
const defaultMaxFileSizeLimitedToInMb: number = 100;
const selectedFile = this.databaseFilesTable.selectedRows !== undefined ? this.objectInfo.files[this.databaseFilesTable?.selectedRows[0]] : undefined;
if (!isUndefinedOrNull(selectedFile) && selectedFile.type === localizedConstants.FilestreamFileType) {
selectedFile.autoFileGrowth = defaultFileGrowthInMb;
}
const isNewFile: boolean = button.ariaLabel === localizedConstants.AddButton;
const isEditingNewFile: boolean = button.ariaLabel === localizedConstants.EditButton && selectedFile.id === undefined;
const databaseFile: DatabaseFile = isNewFile ? {
id: undefined,
name: '',
type: localizedConstants.RowsDataFileType,
path: this.objectInfo.files[0].path,
fileGroup: this.rowDatafileGroupsOptions.find(option => option === 'PRIMARY'),
fileNameWithExtension: '',
sizeInMb: defaultFileSizeInMb,
isAutoGrowthEnabled: true,
autoFileGrowth: defaultFileGrowthInMb,
autoFileGrowthType: FileGrowthType.KB,
maxSizeLimitInMb: defaultMaxFileSizeLimitedToInMb
} : selectedFile;
const dialog = new DatabaseFileDialog({
title: (isNewFile || isEditingNewFile) ? localizedConstants.AddDatabaseFilesText : localizedConstants.EditDatabaseFilesText(databaseFile.name),
viewInfo: this.viewInfo,
files: this.objectInfo.files,
rowFilegroups: this.rowDatafileGroupsOptions,
filestreamFilegroups: this.filestreamDatafileGroupsOptions,
isNewFile: isNewFile,
isEditingNewFile: isEditingNewFile,
databaseFile: databaseFile,
defaultFileConstants: {
defaultFileSizeInMb: defaultFileSizeInMb,
defaultFileGrowthInMb: defaultFileGrowthInMb,
defaultFileGrowthInPercent: defaultFileGrowthInPercent,
defaultMaxFileSizeLimitedToInMb: defaultMaxFileSizeLimitedToInMb
},
connectionUri: this.options.connectionUri
}, this.objectManagementService);
await dialog.open();
return await dialog.waitForClose();
}
//#endregion
//#region Database Properties - FileGroups Tab
/**
* Initializes the rows filegroups section and updates the table data
* @returns Row data filegroups container
*/
private async initializeRowsFileGroupSection(): Promise<azdata.GroupContainer> {
const data = this.getTableData(FileGroupType.RowsFileGroup);
this.rowsFilegroupsTable = this.modelView.modelBuilder.table().withProps({
columns: [{
type: azdata.ColumnType.text,
value: localizedConstants.NameText,
width: 120
}, {
type: azdata.ColumnType.text,
value: localizedConstants.FilesText,
width: 60
}, {
type: azdata.ColumnType.checkBox,
value: localizedConstants.ReadOnlyText,
width: 80
}, {
type: azdata.ColumnType.checkBox,
value: localizedConstants.DefaultText,
width: 80
}, {
type: azdata.ColumnType.checkBox,
value: localizedConstants.AutogrowAllFilesText,
width: 110
}],
data: data,
height: getTableHeight(data.length, DefaultMinTableRowCount, DefaultMaxTableRowCount),
width: DefaultTableWidth,
forceFitColumns: azdata.ColumnSizingMode.DataFit,
CSSStyles: {
'margin-left': '10px'
}
}).component();
this.rowsFilegroupNameInput = this.getFilegroupNameInput(this.rowsFilegroupsTable, FileGroupType.RowsFileGroup);
const addButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.AddFilegroupText,
buttonHandler: () => this.onAddDatabaseFileGroupsButtonClicked(this.rowsFilegroupsTable)
};
const removeButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.RemoveButton,
buttonHandler: () => this.onAddDatabaseFileGroupsButtonClicked(this.rowsFilegroupsTable)
};
const rowsFileGroupButtonContainer = this.addButtonsForTable(this.rowsFilegroupsTable, addButtonComponent, removeButtonComponent);
this.disposables.push(
this.rowsFilegroupsTable.onCellAction(async (arg: azdata.ICheckboxCellActionEventArgs) => {
let filegroup = this.rowDataFileGroupsTableRows[arg.row];
// Read-Only column
if (arg.column === 2) {
filegroup.isReadOnly = arg.checked;
}
// Default column
if (arg.column === 3) {
this.updateFilegroupsDefaultColumnValues(arg, filegroup, FileGroupType.RowsFileGroup);
}
// Autogrow all files column
if (arg.column === 4) {
filegroup.autogrowAllFiles = arg.checked;
}
// Refresh the table with updated data
let data = this.getTableData(FileGroupType.RowsFileGroup);
await this.setTableData(this.rowsFilegroupsTable, data);
this.onFormFieldChange();
}),
this.rowsFilegroupsTable.onRowSelected(
async () => {
if (this.rowsFilegroupsTable.selectedRows.length === 1) {
const fileGroup = this.rowDataFileGroupsTableRows[this.rowsFilegroupsTable.selectedRows[0]];
await this.rowsFilegroupNameInput.updateCssStyles({ 'visibility': fileGroup.id < 0 ? 'visible' : 'hidden' });
this.rowsFilegroupNameInput.value = fileGroup.name;
this.onFormFieldChange();
}
}
)
);
const rowContainer = this.modelView.modelBuilder.flexContainer().withItems([this.rowsFilegroupNameInput]).component();
rowContainer.addItems([rowsFileGroupButtonContainer], { flex: '0 0 auto' });
return this.createGroup(localizedConstants.RowsFileGroupsSectionText, [this.rowsFilegroupsTable, rowContainer], true);
}
/**
* Initializes the filestream filegroups section and updates the table data
* @returns filestream data filegroups container
*/
private initializeFileStreamFileGroupSection(): azdata.GroupContainer {
const data = this.getTableData(FileGroupType.FileStreamDataFileGroup);
this.filestreamFilegroupsTable = this.modelView.modelBuilder.table().withProps({
columns: [{
type: azdata.ColumnType.text,
value: localizedConstants.NameText
}, {
type: azdata.ColumnType.text,
value: localizedConstants.FilestreamFilesText
}, {
type: azdata.ColumnType.checkBox,
value: localizedConstants.ReadOnlyText
}, {
type: azdata.ColumnType.checkBox,
value: localizedConstants.DefaultText
}],
data: data,
height: getTableHeight(data.length, DefaultMinTableRowCount, DefaultMaxTableRowCount),
width: DefaultTableWidth,
forceFitColumns: azdata.ColumnSizingMode.DataFit,
CSSStyles: {
'margin-left': '10px'
}
}).component();
this.filestreamFilegroupNameInput = this.getFilegroupNameInput(this.filestreamFilegroupsTable, FileGroupType.FileStreamDataFileGroup);
const addButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.AddFilegroupText,
buttonHandler: () => this.onAddDatabaseFileGroupsButtonClicked(this.filestreamFilegroupsTable)
};
const removeButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.RemoveButton,
buttonHandler: () => this.onRemoveDatabaseFileGroupsButtonClicked(this.filestreamFilegroupsTable)
};
const filestreamFileGroupButtonContainer = this.addButtonsForTable(this.filestreamFilegroupsTable, addButtonComponent, removeButtonComponent);
this.disposables.push(
this.filestreamFilegroupsTable.onCellAction(async (arg: azdata.ICheckboxCellActionEventArgs) => {
let filegroup = this.filestreamDataFileGroupsTableRows[arg.row];
// Read-Only column
if (arg.column === 2) {
filegroup.isReadOnly = arg.checked;
}
// Default column
else if (arg.column === 3) {
this.updateFilegroupsDefaultColumnValues(arg, filegroup, FileGroupType.FileStreamDataFileGroup);
}
// Refresh the table with updated data
let data = this.getTableData(FileGroupType.FileStreamDataFileGroup);
await this.setTableData(this.filestreamFilegroupsTable, data);
this.onFormFieldChange();
}),
this.filestreamFilegroupsTable.onRowSelected(
async () => {
if (this.filestreamFilegroupsTable.selectedRows.length === 1) {
const fileGroup = this.filestreamDataFileGroupsTableRows[this.filestreamFilegroupsTable.selectedRows[0]];
await this.filestreamFilegroupNameInput.updateCssStyles({ 'visibility': fileGroup.id < 0 ? 'visible' : 'hidden' });
this.filestreamFilegroupNameInput.value = fileGroup.name;
this.onFormFieldChange();
}
}
)
);
const filestreamContainer = this.modelView.modelBuilder.flexContainer().withItems([this.filestreamFilegroupNameInput]).component();
filestreamContainer.addItems([filestreamFileGroupButtonContainer], { flex: '0 0 auto' });
return this.createGroup(localizedConstants.FileStreamFileGroupsSectionText, [this.filestreamFilegroupsTable, filestreamContainer], true);
}
/**
* Initializes the memory optimized filegroups section and updates the table data
* @returns Memory optimized filegroups container
*/
private initializeMemoryOptimizedFileGroupSection(): azdata.GroupContainer {
const data = this.getTableData(FileGroupType.MemoryOptimizedDataFileGroup);
this.memoryOptimizedFilegroupsTable = this.modelView.modelBuilder.table().withProps({
columns: [{
type: azdata.ColumnType.text,
value: localizedConstants.NameText
}, {
type: azdata.ColumnType.text,
value: localizedConstants.FilestreamFilesText
}],
data: data,
height: getTableHeight(data.length, DefaultMinTableRowCount, DefaultMaxTableRowCount),
width: DefaultTableWidth,
forceFitColumns: azdata.ColumnSizingMode.DataFit,
CSSStyles: {
'margin-left': '10px'
}
}).component();
this.memoryOptimizedFilegroupNameInput = this.getFilegroupNameInput(this.memoryOptimizedFilegroupsTable, FileGroupType.MemoryOptimizedDataFileGroup);
const addButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.AddFilegroupText,
buttonHandler: () => this.onAddDatabaseFileGroupsButtonClicked(this.memoryOptimizedFilegroupsTable),
enabled: this.memoryoptimizedFileGroupsTableRows.length < 1
};
const removeButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.RemoveButton,
buttonHandler: () => this.onRemoveDatabaseFileGroupsButtonClicked(this.memoryOptimizedFilegroupsTable)
};
const memoryOptimizedFileGroupButtonContainer = this.addButtonsForTable(this.memoryOptimizedFilegroupsTable, addButtonComponent, removeButtonComponent);
this.disposables.push(
this.memoryOptimizedFilegroupsTable.onRowSelected(
async () => {
if (this.memoryOptimizedFilegroupsTable.selectedRows.length === 1) {
const fileGroup = this.memoryoptimizedFileGroupsTableRows[this.memoryOptimizedFilegroupsTable.selectedRows[0]];
await this.memoryOptimizedFilegroupNameInput.updateCssStyles({ 'visibility': fileGroup.id < 0 ? 'visible' : 'hidden' });
this.memoryOptimizedFilegroupNameInput.value = fileGroup.name;
this.onFormFieldChange();
}
}
)
);
const memoryOptimizedContainer = this.modelView.modelBuilder.flexContainer().withItems([this.memoryOptimizedFilegroupNameInput]).component();
memoryOptimizedContainer.addItems([memoryOptimizedFileGroupButtonContainer], { flex: '0 0 auto' });
return this.createGroup(localizedConstants.MemoryOptimizedFileGroupsSectionText, [this.memoryOptimizedFilegroupsTable, memoryOptimizedContainer], true);
}
/**
* Overrides declarative table add button enabled/disabled state
* @param table table component
* @returns table add button enabled/disabled state
*/
public override addButtonEnabled(table: azdata.TableComponent | azdata.DeclarativeTableComponent): boolean {
let enabled = true;
if (table === this.memoryOptimizedFilegroupsTable) {
enabled = this.memoryoptimizedFileGroupsTableRows.length < 1;
}
return enabled;
}
/**
* Update the default value for the filegroup
* @param arg selected checkbox event
* @param filegroup filegroup object
* @param filegroupType filegroup type
*/
private updateFilegroupsDefaultColumnValues(arg: azdata.ICheckboxCellActionEventArgs, filegroup: FileGroup, filegroupType: FileGroupType): void {
if (arg.checked) {
this.objectInfo.filegroups.forEach(fg => {
if (fg.type === filegroupType) {
fg.isDefault = fg.name === filegroup.name && fg.id === filegroup.id ? arg.checked : !arg.checked;
}
});
} else {
filegroup.isDefault = arg.checked;
}
}
/**
* Adding new row to the respective table on its add button click
* @param table table component
*/
private async onAddDatabaseFileGroupsButtonClicked(table: azdata.TableComponent): Promise<void> {
let newData: any[] | undefined;
let newRow: FileGroup = {
id: --this.newFileGroupTemporaryId,
name: '',
type: undefined,