foreign_key_row.twig 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <tr>
  2. {# Drop key anchor #}
  3. <td>
  4. {% set js_msg = '' %}
  5. {% set this_params = null %}
  6. {% if one_key['constraint'] is defined %}
  7. {% set drop_fk_query = 'ALTER TABLE ' ~ backquote(db) ~ '.' ~ backquote(table)
  8. ~ ' DROP FOREIGN KEY '
  9. ~ backquote(one_key['constraint']) ~ ';'
  10. %}
  11. {% set this_params = url_params %}
  12. {% set this_params = {
  13. 'goto': url('/table/relation'),
  14. 'back': url('/table/relation'),
  15. 'sql_query': drop_fk_query,
  16. 'message_to_show': 'Foreign key constraint %s has been dropped'|trans|format(
  17. one_key['constraint']
  18. )
  19. } %}
  20. {% set js_msg = 'ALTER TABLE ' ~ db ~ '.' ~ table ~ ' DROP FOREIGN KEY ' ~ one_key['constraint'] ~ ';'|js_format %}
  21. {% endif %}
  22. {% if one_key['constraint'] is defined %}
  23. <input type="hidden" class="drop_foreign_key_msg" value="
  24. {{- js_msg }}">
  25. {% set drop_url = url('/sql', this_params) %}
  26. {% set drop_str = get_icon('b_drop', 'Drop'|trans) %}
  27. {{ link_or_button(drop_url, drop_str, {'class': 'drop_foreign_key_anchor ajax'}) }}
  28. {% endif %}
  29. </td>
  30. <td>
  31. <span class="formelement clearfloat">
  32. <input type="text" name="constraint_name[{{ i }}]" value="
  33. {{- one_key['constraint'] is defined ? one_key['constraint'] -}}
  34. " placeholder="{% trans 'Constraint name' %}" maxlength="64">
  35. </span>
  36. <div class="floatleft">
  37. {# For ON DELETE and ON UPDATE, the default action
  38. is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE
  39. won't display the clause if it's set as RESTRICT. #}
  40. {% set on_delete = one_key['on_delete'] is defined
  41. ? one_key['on_delete'] : 'RESTRICT' %}
  42. {% set on_update = one_key['on_update'] is defined
  43. ? one_key['on_update'] : 'RESTRICT' %}
  44. <span class="formelement">
  45. {% include 'table/relation/dropdown_generate.twig' with {
  46. 'dropdown_question': 'ON DELETE',
  47. 'select_name': 'on_delete[' ~ i ~ ']',
  48. 'choices': options_array,
  49. 'selected_value': on_delete
  50. } only %}
  51. </span>
  52. <span class="formelement">
  53. {% include 'table/relation/dropdown_generate.twig' with {
  54. 'dropdown_question': 'ON UPDATE',
  55. 'select_name': 'on_update[' ~ i ~ ']',
  56. 'choices': options_array,
  57. 'selected_value': on_update
  58. } only %}
  59. </span>
  60. </div>
  61. </td>
  62. <td>
  63. {% if one_key['index_list'] is defined %}
  64. {% for key, column in one_key['index_list'] %}
  65. <span class="formelement clearfloat">
  66. {% include 'table/relation/dropdown_generate.twig' with {
  67. 'dropdown_question': '',
  68. 'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
  69. 'choices': column_array,
  70. 'selected_value': column
  71. } only %}
  72. </span>
  73. {% endfor %}
  74. {% else %}
  75. <span class="formelement clearfloat">
  76. {% include 'table/relation/dropdown_generate.twig' with {
  77. 'dropdown_question': '',
  78. 'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
  79. 'choices': column_array,
  80. 'selected_value': ''
  81. } only %}
  82. </span>
  83. {% endif %}
  84. <a class="formelement clearfloat add_foreign_key_field" data-index="
  85. {{- i }}" href="">
  86. {% trans '+ Add column' %}
  87. </a>
  88. </td>
  89. {% set tables = [] %}
  90. {% if foreign_db %}
  91. {% set tables = get_tables(foreign_db, tbl_storage_engine) %}
  92. {% else %}
  93. {% set tables = get_tables(db, tbl_storage_engine) %}
  94. {% endif %}
  95. <td>
  96. <span class="formelement clearfloat">
  97. {% include 'table/relation/relational_dropdown.twig' with {
  98. 'name': 'destination_foreign_db[' ~ i ~ ']',
  99. 'title': 'Database'|trans,
  100. 'values': databases,
  101. 'foreign': foreign_db,
  102. 'db': db
  103. } only %}
  104. </span>
  105. </td>
  106. <td>
  107. <span class="formelement clearfloat">
  108. {% include 'table/relation/relational_dropdown.twig' with {
  109. 'name': 'destination_foreign_table[' ~ i ~ ']',
  110. 'title': 'Table'|trans,
  111. 'values': tables,
  112. 'foreign': foreign_table
  113. } only %}
  114. </span>
  115. </td>
  116. <td>
  117. {% if foreign_db and foreign_table %}
  118. {% for foreign_column in one_key['ref_index_list'] %}
  119. <span class="formelement clearfloat">
  120. {% include 'table/relation/relational_dropdown.twig' with {
  121. 'name': 'destination_foreign_column[' ~ i ~ '][]',
  122. 'title': 'Column'|trans,
  123. 'values': unique_columns,
  124. 'foreign': foreign_column
  125. } only %}
  126. </span>
  127. {% endfor %}
  128. {% else %}
  129. <span class="formelement clearfloat">
  130. {% include 'table/relation/relational_dropdown.twig' with {
  131. 'name': 'destination_foreign_column[' ~ i ~ '][]',
  132. 'title': 'Column'|trans,
  133. 'values': [],
  134. 'foreign': ''
  135. } only %}
  136. </span>
  137. {% endif %}
  138. </td>
  139. </tr>