@@ -14,7 +14,7 @@ import i18n from '@tap/i18n'
1414import { setPageTitle } from '@tap/shared'
1515import dagre from 'dagre'
1616import dayjs from 'dayjs'
17- import { merge } from 'lodash-es'
17+ import { isEmpty , merge } from 'lodash-es'
1818import Mousetrap from 'mousetrap'
1919import { h , markRaw } from 'vue'
2020import { mapActions , mapGetters , mapMutations , mapState } from 'vuex'
@@ -1820,7 +1820,7 @@ export default {
18201820 }
18211821 } ,
18221822
1823- async validateMigrateUnion ( ) {
1823+ validateMigrateUnion ( ) {
18241824 if ( this . dataflow . syncType !== 'migrate' ) return
18251825
18261826 const nodes = this . allNodes . filter (
@@ -1830,7 +1830,7 @@ export default {
18301830 if ( nodes . length > 1 ) return i18n . t ( 'packages_dag_migrate_union_multiple' )
18311831 } ,
18321832
1833- async validateMergeTableProcessor ( ) {
1833+ validateMergeTableProcessor ( ) {
18341834 if ( this . dataflow . syncType === 'migrate' ) return
18351835
18361836 const nodes = this . allNodes . filter (
@@ -1908,6 +1908,72 @@ export default {
19081908 }
19091909 } ,
19101910
1911+ validateDmlPolicy ( ) {
1912+ if ( this . dataflow . syncType !== 'migrate' ) return
1913+
1914+ const target = this . allNodes . find (
1915+ ( node ) => node . type === 'database' && ! node . $outputs . length ,
1916+ )
1917+
1918+ if ( target && isEmpty ( target . dmlPolicy ) ) {
1919+ const capabilities = target . attrs . capabilities
1920+ const insertPolicy = capabilities ?. find (
1921+ ( { id } ) => id === 'dml_insert_policy' ,
1922+ )
1923+ const updatePolicy = capabilities ?. find (
1924+ ( { id } ) => id === 'dml_update_policy' ,
1925+ )
1926+ const deletePolicy = capabilities ?. find (
1927+ ( { id } ) => id === 'dml_delete_policy' ,
1928+ )
1929+
1930+ const insertOptions = [
1931+ 'update_on_exists' ,
1932+ 'ignore_on_exists' ,
1933+ 'just_insert' ,
1934+ ]
1935+ const updateOptions = [
1936+ 'ignore_on_nonexists' ,
1937+ 'insert_on_nonexists' ,
1938+ 'log_on_nonexists' ,
1939+ ]
1940+ const deleteOptions = [ 'ignore_on_nonexists' , 'log_on_nonexists' ]
1941+ const dmlPolicy = { }
1942+
1943+ if ( insertPolicy ?. alternatives ?. length ) {
1944+ dmlPolicy . insertPolicy = insertOptions [ 0 ]
1945+ const alternatives = insertPolicy . alternatives . filter ( ( key ) =>
1946+ insertOptions . includes ( key ) ,
1947+ )
1948+ if ( alternatives . length === 1 ) {
1949+ dmlPolicy . insertPolicy = alternatives [ 0 ]
1950+ }
1951+ }
1952+
1953+ if ( updatePolicy ?. alternatives ?. length ) {
1954+ dmlPolicy . updatePolicy = updateOptions [ 0 ]
1955+ const alternatives = updatePolicy . alternatives . filter ( ( key ) =>
1956+ updateOptions . includes ( key ) ,
1957+ )
1958+ if ( alternatives . length === 1 ) {
1959+ dmlPolicy . updatePolicy = alternatives [ 0 ]
1960+ }
1961+ }
1962+
1963+ if ( deletePolicy ?. alternatives ?. length ) {
1964+ dmlPolicy . deletePolicy = deleteOptions [ 0 ]
1965+ const alternatives = deletePolicy . alternatives . filter ( ( key ) =>
1966+ deleteOptions . includes ( key ) ,
1967+ )
1968+ if ( alternatives . length === 1 ) {
1969+ dmlPolicy . deletePolicy = alternatives [ 0 ]
1970+ }
1971+ }
1972+
1973+ target . dmlPolicy = dmlPolicy
1974+ }
1975+ } ,
1976+
19111977 async eachValidate ( ...fns ) {
19121978 for ( const fn of fns ) {
19131979 let result = fn ( )
@@ -1946,6 +2012,7 @@ export default {
19462012 this . validateTableRename ,
19472013 this . validateMigrateUnion ,
19482014 this . validateMergeTableProcessor ,
2015+ this . validateDmlPolicy ,
19492016 )
19502017 } ,
19512018
0 commit comments