mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 08:01:25 +00:00
Refactor + handle datatable setting delete/rename
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM datatable_migrations WHERE workspace_id = $1 AND datatable = ANY($2::text[])",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"TextArray"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "00e9fc3fed9379264881c58df9404ab3569a0611b33c261602d62e9c847c583e"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE datatable_migrations SET datatable = $3 WHERE workspace_id = $1 AND datatable = $2",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"Varchar"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "2c543583bcf7bcaf2f422638ce0741a2e193f18ffa11d08e8ca49cef5c3b850c"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
||||
pub mod datatable_migrations;
|
||||
pub mod deployment_requests;
|
||||
pub mod workspaces;
|
||||
pub mod workspaces_extra;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4515,6 +4515,22 @@ paths:
|
||||
properties:
|
||||
settings:
|
||||
$ref: "#/components/schemas/DataTableSettings"
|
||||
renames:
|
||||
description: data tables renamed in this save, so their migrations cascade
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
required: [from, to]
|
||||
properties:
|
||||
from:
|
||||
type: string
|
||||
to:
|
||||
type: string
|
||||
deleted_datatables:
|
||||
description: data tables removed in this save, so their migrations are deleted
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: status
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
<script lang="ts" module>
|
||||
import { randomUUID } from '$lib/utils/uuid'
|
||||
|
||||
export type DataTableSettingsType = {
|
||||
dataTables: {
|
||||
// Stable client-side id so the UI can track renames (A -> B) across a
|
||||
// save rather than seeing them as a delete + add. Never sent to the
|
||||
// backend config.
|
||||
id: string
|
||||
name: string
|
||||
database: {
|
||||
resource_type: 'postgresql' | 'instance'
|
||||
@@ -16,6 +22,7 @@
|
||||
if (settings?.datatables) {
|
||||
for (const [name, rest] of Object.entries(settings.datatables)) {
|
||||
s.dataTables.push({
|
||||
id: randomUUID(),
|
||||
name,
|
||||
...rest
|
||||
})
|
||||
@@ -115,6 +122,7 @@
|
||||
? `${random_adj()}_datatable`
|
||||
: 'main'
|
||||
tempSettings.dataTables.push({
|
||||
id: randomUUID(),
|
||||
name,
|
||||
database: {
|
||||
resource_type: $isCustomInstanceDbEnabled ? 'instance' : 'postgresql',
|
||||
@@ -141,9 +149,19 @@
|
||||
if (!confirm) return
|
||||
}
|
||||
const settings = convertDataTableSettingsToBackend(tempSettings)
|
||||
// Track renames/deletions by stable id (against the saved baseline) so
|
||||
// the backend can cascade or delete each data table's migrations.
|
||||
const savedById = new Map(dataTableSettings.dataTables.map((d) => [d.id, d.name]))
|
||||
const tempIds = new Set(tempSettings.dataTables.map((d) => d.id))
|
||||
const renames = tempSettings.dataTables
|
||||
.filter((d) => savedById.has(d.id) && savedById.get(d.id) !== d.name)
|
||||
.map((d) => ({ from: savedById.get(d.id)!, to: d.name }))
|
||||
const deleted_datatables = dataTableSettings.dataTables
|
||||
.filter((d) => !tempIds.has(d.id))
|
||||
.map((d) => d.name)
|
||||
await WorkspaceService.editDataTableConfig({
|
||||
workspace: $workspaceStore!,
|
||||
requestBody: { settings }
|
||||
requestBody: { settings, renames, deleted_datatables }
|
||||
})
|
||||
dataTableSettings = clone(tempSettings)
|
||||
sendUserToast('Data table settings saved successfully')
|
||||
@@ -159,7 +177,7 @@
|
||||
const map: Record<string, boolean> = {}
|
||||
for (let i = 0; i < tempSettings.dataTables.length; i++) {
|
||||
let temp = tempSettings.dataTables[i]
|
||||
let dt = dataTableSettings.dataTables.find((d) => d.name === temp.name)
|
||||
let dt = dataTableSettings.dataTables.find((d) => d.id === temp.id)
|
||||
map[temp.name] = !deepEqual(dt, temp)
|
||||
}
|
||||
return map
|
||||
@@ -219,7 +237,7 @@
|
||||
</Cell>
|
||||
</Row>
|
||||
{/if}
|
||||
{#each tempSettings.dataTables as dataTable, dataTableIndex}
|
||||
{#each tempSettings.dataTables as dataTable, dataTableIndex (dataTable.id)}
|
||||
<Row>
|
||||
<Cell first class="w-48 relative">
|
||||
<TextInput bind:value={dataTable.name} inputProps={{ placeholder: 'Name', id: 'name' }} />
|
||||
|
||||
Reference in New Issue
Block a user