(actions: ActionProto[], declarationTargets: dataform.ITarget[])
| 651 | } |
| 652 | |
| 653 | private alterActionName(actions: ActionProto[], declarationTargets: dataform.ITarget[]) { |
| 654 | const { tablePrefix, schemaSuffix, databaseSuffix } = this.projectConfig; |
| 655 | |
| 656 | if (!tablePrefix && !schemaSuffix && !databaseSuffix) { |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | const newTargetByOriginalTarget = new Map<string, dataform.ITarget>(); |
| 661 | declarationTargets.forEach(declarationTarget => |
| 662 | newTargetByOriginalTarget.set( |
| 663 | targetStringifier.stringify(declarationTarget), |
| 664 | declarationTarget |
| 665 | ) |
| 666 | ); |
| 667 | |
| 668 | actions.forEach(action => { |
| 669 | newTargetByOriginalTarget.set(targetStringifier.stringify(action.target), { |
| 670 | ...action.target, |
| 671 | database: |
| 672 | action.target.database && |
| 673 | `${action.target.database}${this.getDatabaseSuffixWithUnderscore()}`, |
| 674 | schema: `${action.target.schema}${this.getSchemaSuffixWithUnderscore()}`, |
| 675 | name: `${this.getTablePrefixWithUnderscore()}${action.target.name}` |
| 676 | }); |
| 677 | action.target = newTargetByOriginalTarget.get(targetStringifier.stringify(action.target)); |
| 678 | }); |
| 679 | |
| 680 | // Fix up dependencies in case those dependencies' names have changed. |
| 681 | const getUpdatedTarget = (originalTarget: dataform.ITarget) => { |
| 682 | // It's possible that we don't have a new Target for a dependency that failed to compile, |
| 683 | // so fall back to the original Target. |
| 684 | if (!newTargetByOriginalTarget.has(targetStringifier.stringify(originalTarget))) { |
| 685 | return originalTarget; |
| 686 | } |
| 687 | return newTargetByOriginalTarget.get(targetStringifier.stringify(originalTarget)); |
| 688 | }; |
| 689 | actions.forEach(action => { |
| 690 | if (!(action instanceof dataform.Declaration)) { |
| 691 | // Declarations cannot have dependencies. |
| 692 | action.dependencyTargets = (action.dependencyTargets || []).map(getUpdatedTarget); |
| 693 | } |
| 694 | |
| 695 | if (action instanceof dataform.Assertion && !!action.parentAction) { |
| 696 | action.parentAction = getUpdatedTarget(action.parentAction); |
| 697 | } |
| 698 | }); |
| 699 | } |
| 700 | |
| 701 | private checkTestNameUniqueness(tests: dataform.ITest[]) { |
| 702 | const allNames: string[] = []; |
no test coverage detected