Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Remove sync_status, last_successful_sync_ts from tbl, idx, col table and we just recreate the entry every time doing the sync

天舟dc3861eba2ed
diff --git a/api/column.go b/api/column.go
index ca41a5b4b2..1eb90059e4 100644
--- a/api/column.go
+++ b/api/column.go
@@ -19,16 +19,14 @@ type Column struct {
TableId int
// Domain specific fields
- SyncStatus SyncStatus `json:"syncStatus"`
- LastSuccessfulSyncTs int64 `json:"lastSuccessfulSyncTs"`
- Name string `json:"name"`
- Position int `json:"position"`
- Default *string `json:"default"`
- Nullable bool `json:"nullable"`
- Type string `json:"type"`
- CharacterSet string `json:"characterSet"`
- Collation string `json:"collation"`
- Comment string `json:"comment"`
+ Name string `json:"name"`
+ Position int `json:"position"`
+ Default *string `json:"default"`
+ Nullable bool `json:"nullable"`
+ Type string `json:"type"`
+ CharacterSet string `json:"characterSet"`
+ Collation string `json:"collation"`
+ Comment string `json:"comment"`
}
type ColumnCreate struct {
@@ -76,10 +74,6 @@ type ColumnPatch struct {
// Standard fields
// Value is assigned from the jwt subject field passed by the client.
UpdaterId int
-
- // Domain specific fields
- SyncStatus *SyncStatus
- LastSuccessfulSyncTs *int64
}
type ColumnService interface {
diff --git a/api/table.go b/api/table.go
index 2fd129b2c1..6f53f62be4 100644
--- a/api/table.go
+++ b/api/table.go
@@ -21,20 +21,18 @@ type Table struct {
Database *Database `jsonapi:"relation,database"`
// Domain specific fields
- Name string `jsonapi:"attr,name"`
- Type string `jsonapi:"attr,type"`
- Engine string `jsonapi:"attr,engine"`
- Collation string `jsonapi:"attr,collation"`
- SyncStatus SyncStatus `jsonapi:"attr,syncStatus"`
- LastSuccessfulSyncTs int64 `jsonapi:"attr,lastSuccessfulSyncTs"`
- RowCount int64 `jsonapi:"attr,rowCount"`
- DataSize int64 `jsonapi:"attr,dataSize"`
- IndexSize int64 `jsonapi:"attr,indexSize"`
- DataFree int64 `jsonapi:"attr,dataFree"`
- CreateOptions string `jsonapi:"attr,createOptions"`
- Comment string `jsonapi:"attr,comment"`
- ColumnList []*Column `jsonapi:"attr,columnList"`
- IndexList []*Index `jsonapi:"attr,indexList"`
+ Name string `jsonapi:"attr,name"`
+ Type string `jsonapi:"attr,type"`
+ Engine string `jsonapi:"attr,engine"`
+ Collation string `jsonapi:"attr,collation"`
+ RowCount int64 `jsonapi:"attr,rowCount"`
+ DataSize int64 `jsonapi:"attr,dataSize"`
+ IndexSize int64 `jsonapi:"attr,indexSize"`
+ DataFree int64 `jsonapi:"attr,dataFree"`
+ CreateOptions string `jsonapi:"attr,createOptions"`
+ Comment string `jsonapi:"attr,comment"`
+ ColumnList []*Column `jsonapi:"attr,columnList"`
+ IndexList []*Index `jsonapi:"attr,indexList"`
}
type TableCreate struct {
@@ -82,10 +80,11 @@ type TablePatch struct {
// Standard fields
// Value is assigned from the jwt subject field passed by the client.
UpdaterId int
+}
- // Domain specific fields
- SyncStatus *SyncStatus
- LastSuccessfulSyncTs *int64
+type TableDelete struct {
+ // Related fields
+ DatabaseId int
}
type TableService interface {
@@ -93,4 +92,5 @@ type TableService interface {
FindTableList(ctx context.Context, find *TableFind) ([]*Table, error)
FindTable(ctx context.Context, find *TableFind) (*Table, error)
PatchTable(ctx context.Context, patch *TablePatch) (*Table, error)
+ DeleteTable(ctx context.Context, delete *TableDelete) error
}
diff --git a/api/table_index.go b/api/table_index.go
index c288bbb081..e81b06519b 100644
--- a/api/table_index.go
+++ b/api/table_index.go
@@ -19,15 +19,13 @@ type Index struct {
TableId int
// Domain specific fields
- SyncStatus SyncStatus `json:"syncStatus"`
- LastSuccessfulSyncTs int64 `json:"lastSuccessfulSyncTs"`
- Name string `json:"name"`
- Expression string `json:"expression"`
- Position int `json:"position"`
- Type string `json:"type"`
- Unique bool `json:"unique"`
- Visible bool `json:"visible"`
- Comment string `json:"comment"`
+ Name string `json:"name"`
+ Expression string `json:"expression"`
+ Position int `json:"position"`
+ Type string `json:"type"`
+ Unique bool `json:"unique"`
+ Visible bool `json:"visible"`
+ Comment string `json:"comment"`
}
type IndexCreate struct {
@@ -75,10 +73,6 @@ type IndexPatch struct {
// Standard fields
// Value is assigned from the jwt subject field passed by the client.
UpdaterId int
-
- // Domain specific fields
- SyncStatus *SyncStatus
- LastSuccessfulSyncTs *int64
}
type IndexService interface {
diff --git a/frontend/src/components/ColumnTable.vue b/frontend/src/components/ColumnTable.vue
index 349e0088b7..e022183e5b 100644
--- a/frontend/src/components/ColumnTable.vue
+++ b/frontend/src/components/ColumnTable.vue
@@ -28,12 +28,6 @@
<BBTableCell class="w-16">
{{ column.comment }}
</BBTableCell>
- <BBTableCell class="w-8">
- {{ column.syncStatus }}
- </BBTableCell>
- <BBTableCell class="w-16">
- {{ humanizeTs(column.lastSuccessfulSyncTs) }}
- </BBTableCell>
</template>
</BBTable>
</template>
@@ -65,12 +59,6 @@ const COLUMN_LIST: BBTableColumn[] = [
{
title: "Comment",
},
- {
- title: "Sync status",
- },
- {
- title: "Last successful sync",
- },
];
export default {
diff --git a/frontend/src/components/IndexTable.vue b/frontend/src/components/IndexTable.vue
index 6a76d3c0ca..68f344dee9 100644
--- a/frontend/src/components/IndexTable.vue
+++ b/frontend/src/components/IndexTable.vue
@@ -34,12 +34,6 @@
<BBTableCell>
{{ index.comment }}
</BBTableCell>
- <BBTableCell>
- {{ index.syncStatus }}
- </BBTableCell>
- <BBTableCell>
- {{ humanizeTs(index.lastSuccessfulSyncTs) }}
- </BBTableCell>
</template>
</BBTable>
</template>
@@ -65,12 +59,6 @@ const COLUMN_LIST: BBTableColumn[] = [
{
title: "Comment",
},
- {
- title: "Sync status",
- },
- {
- title: "Last successful sync",
- },
];
export default {
diff --git a/frontend/src/components/TableTable.vue b/frontend/src/components/TableTable.vue
index 23522acfa2..79377f47e3 100644
--- a/frontend/src/components/TableTable.vue
+++ b/frontend/src/components/TableTable.vue
@@ -24,12 +24,6 @@
<BBTableCell v-if="mode == 'TABLE'" class="w-8">
{{ bytesToString(table.indexSize) }}
</BBTableCell>
- <BBTableCell class="w-8">
- {{ table.syncStatus }}
- </BBTableCell>
- <BBTableCell class="w-16">
- {{ humanizeTs(table.lastSuccessfulSyncTs) }}
- </BBTableCell>
</template>
</BBTable>
</template>
@@ -63,12 +57,6 @@ const columnListMap: Map<Mode, BBTableColumn[]> = new Map([
{
title: "Index size",
},
- {
- title: "Sync status",
- },
- {
- title: "Last successful sync",
- },
],
],
[
@@ -77,12 +65,6 @@ const columnListMap: Map<Mode, BBTableColumn[]> = new Map([
{
title: "Name",
},
- {
- title: "Sync status",
- },
- {
- title: "Last successful sync",
- },
],
],
]);
diff --git a/frontend/src/types/column.ts b/frontend/src/types/column.ts
index d8bc035a58..71c3968352 100644
--- a/frontend/src/types/column.ts
+++ b/frontend/src/types/column.ts
@@ -1,8 +1,5 @@
import { ColumnId, DatabaseId, TableId } from "./id";
-// Similar to DatabaseSyncStatus, see comment
-export type ColumnSyncStatus = "OK" | "NOT_FOUND";
-
// Column
export type Column = {
id: ColumnId;
@@ -18,8 +15,6 @@ export type Column = {
updatedTs: number;
// Domain specific fields
- syncStatus: ColumnSyncStatus;
- lastSuccessfulSyncTs: number;
name: string;
position: number;
default: string;
diff --git a/frontend/src/types/table.ts b/frontend/src/types/table.ts
index ec6dc523c5..eac141f0bd 100644
--- a/frontend/src/types/table.ts
+++ b/frontend/src/types/table.ts
@@ -3,8 +3,6 @@ import { Database } from "./database";
import { TableId } from "./id";
import { Principal } from "./principal";
-// Similar to DatabaseSyncStatus, see comment
-export type TableSyncStatus = "OK" | "NOT_FOUND";
export type TableType = "BASE TABLE" | "VIEW";
export type TableEngineType = "InnoDB";
@@ -22,8 +20,6 @@ export type Table = {
updatedTs: number;
// Domain specific fields
- syncStatus: TableSyncStatus;
- lastSuccessfulSyncTs: number;
name: string;
type: TableType;
engine: TableEngineType;
diff --git a/frontend/src/types/tableIndex.ts b/frontend/src/types/tableIndex.ts
index 64a9a80da3..318a008d28 100644
--- a/frontend/src/types/tableIndex.ts
+++ b/frontend/src/types/tableIndex.ts
@@ -1,8 +1,5 @@
import { DatabaseId, TableId, TableIndexId } from "./id";
-// Similar to DatabaseSyncStatus, see comment
-export type IndexSyncStatus = "OK" | "NOT_FOUND";
-
// Index
export type TableIndex = {
id: TableIndexId;
@@ -18,8 +15,6 @@ export type TableIndex = {
updatedTs: number;
// Domain specific fields
- syncStatus: IndexSyncStatus;
- lastSuccessfulSyncTs: number;
name: string;
expression: string;
position: number;
diff --git a/server/sql.go b/server/sql.go
index 9e52e98bc6..e0551b320a 100644
--- a/server/sql.go
+++ b/server/sql.go
@@ -140,6 +140,93 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
return nil
}
+ var recreateTableSchema = func(database *api.Database, table db.DBTable) error {
+ // Table
+ tableCreate := &api.TableCreate{
+ CreatorId: api.SYSTEM_BOT_ID,
+ DatabaseId: database.ID,
+ Name: table.Name,
+ Type: table.Type,
+ Engine: table.Engine,
+ Collation: table.Collation,
+ RowCount: table.RowCount,
+ DataSize: table.DataSize,
+ IndexSize: table.IndexSize,
+ DataFree: table.DataFree,
+ CreateOptions: table.CreateOptions,
+ Comment: table.Comment,
+ }
+ upsertedTable, err := createTable(database, tableCreate)
+ if err != nil {
+ return err
+ }
+
+ // Column
+ for _, column := range table.ColumnList {
+ columnFind := &api.ColumnFind{
+ DatabaseId: &database.ID,
+ TableId: &upsertedTable.ID,
+ Name: &column.Name,
+ }
+ _, err := s.ColumnService.FindColumn(context.Background(), columnFind)
+ if err != nil {
+ if common.ErrorCode(err) == common.ENOTFOUND {
+ columnCreate := &api.ColumnCreate{
+ CreatorId: api.SYSTEM_BOT_ID,
+ DatabaseId: database.ID,
+ TableId: upsertedTable.ID,
+ Name: column.Name,
+ Position: column.Position,
+ Default: column.Default,
+ Nullable: column.Nullable,
+ Type: column.Type,
+ CharacterSet: column.CharacterSet,
+ Collation: column.Collation,
+ Comment: column.Comment,
+ }
+ if err := createColumn(database, upsertedTable, columnCreate); err != nil {
+ return err
+ }
+ } else {
+ return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, err)
+ }
+ }
+ }
+
+ // Index
+ for _, index := range table.IndexList {
+ indexFind := &api.IndexFind{
+ DatabaseId: &database.ID,
+ TableId: &upsertedTable.ID,
+ Name: &index.Name,
+ Expression: &index.Expression,
+ }
+ _, err := s.IndexService.FindIndex(context.Background(), indexFind)
+ if err != nil {
+ if common.ErrorCode(err) == common.ENOTFOUND {
+ indexCreate := &api.IndexCreate{
+ CreatorId: api.SYSTEM_BOT_ID,
+ DatabaseId: database.ID,
+ TableId: upsertedTable.ID,
+ Name: index.Name,
+ Expression: index.Expression,
+ Position: index.Position,
+ Type: index.Type,
+ Unique: index.Unique,
+ Visible: index.Visible,
+ Comment: index.Comment,
+ }
+ if err := createIndex(database, upsertedTable, indexCreate); err != nil {
+ return err
+ }
+ } else {
+ return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, err)
+ }
+ }
+ }
+ return nil
+ }
+
instanceUserFind := &api.InstanceUserFind{
InstanceId: instance.ID,
}
@@ -190,6 +277,10 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
// We don't delete the entry because:
// 1. This entry has already been associated with other entities, we can't simply delete it.
// 2. The deletion in the schema might be a mistake, so it's better to surface as NOT_FOUND to let user review it.
+ //
+ // If we successfully synced a particular db schema, we just recreate its table, index, column info. We do this because
+ // we don't reference those objects and they are for information purpose.
+
databaseFind := &api.DatabaseFind{
InstanceId: &instance.ID,
}
@@ -207,7 +298,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
}
if matchedDb != nil {
- // Case 1
+ // Case 1, appear in both the bytebase metadata and the synced db schema
syncStatus := api.OK
ts := time.Now().Unix()
databasePatch := &api.DatabasePatch{
@@ -224,147 +315,22 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
return fmt.Errorf("failed to sync database for instance: %s. Failed to update database: %s. Error %w", instance.Name, database.Name, err)
}
+ tableDelete := &api.TableDelete{
+ DatabaseId: database.ID,
+ }
+ err = s.TableService.DeleteTable(context.Background(), tableDelete)
+ if err != nil {
+ return fmt.Errorf("failed to sync database for instance: %s. Failed to reset table info for database: %s. Error %w", instance.Name, database.Name, err)
+ }
+
for _, table := range schema.TableList {
- // Table
- tableFind := &api.TableFind{
- DatabaseId: &database.ID,
- Name: &table.Name,
- }
- storedTable, err := s.TableService.FindTable(context.Background(), tableFind)
- var upsertedTable *api.Table
+ err = recreateTableSchema(database, table)
if err != nil {
- if common.ErrorCode(err) == common.ENOTFOUND {
- tableCreate := &api.TableCreate{
- CreatorId: api.SYSTEM_BOT_ID,
- DatabaseId: database.ID,
- Name: table.Name,
- Type: table.Type,
- Engine: table.Engine,
- Collation: table.Collation,
- RowCount: table.RowCount,
- DataSize: table.DataSize,
- IndexSize: table.IndexSize,
- DataFree: table.DataFree,
- CreateOptions: table.CreateOptions,
- Comment: table.Comment,
- }
- upsertedTable, err = createTable(database, tableCreate)
- if err != nil {
- return err
- }
- } else {
- return fmt.Errorf("failed to sync table for instance: %s, database: %s. Error %w", instance.Name, database.Name, err)
- }
- } else {
- tablePatch := &api.TablePatch{
- ID: storedTable.ID,
- UpdaterId: api.SYSTEM_BOT_ID,
- SyncStatus: &syncStatus,
- LastSuccessfulSyncTs: &ts,
- }
- upsertedTable, err = s.TableService.PatchTable(context.Background(), tablePatch)
- if err != nil {
- if common.ErrorCode(err) == common.ENOTFOUND {
- return fmt.Errorf("failed to sync table for instance: %s, database: %s. Table not found: %s", instance.Name, database.Name, storedTable.Name)
- }
- return fmt.Errorf("failed to sync table for instance: %s, database: %s. Failed to update table: %s. Error %w", instance.Name, database.Name, storedTable.Name, err)
- }
- }
-
- // Column
- for _, column := range table.ColumnList {
- columnFind := &api.ColumnFind{
- DatabaseId: &database.ID,
- TableId: &upsertedTable.ID,
- Name: &column.Name,
- }
- storedColumn, err := s.ColumnService.FindColumn(context.Background(), columnFind)
- if err != nil {
- if common.ErrorCode(err) == common.ENOTFOUND {
- columnCreate := &api.ColumnCreate{
- CreatorId: api.SYSTEM_BOT_ID,
- DatabaseId: database.ID,
- TableId: upsertedTable.ID,
- Name: column.Name,
- Position: column.Position,
- Default: column.Default,
- Nullable: column.Nullable,
- Type: column.Type,
- CharacterSet: column.CharacterSet,
- Collation: column.Collation,
- Comment: column.Comment,
- }
- if err := createColumn(database, upsertedTable, columnCreate); err != nil {
- return err
- }
- } else {
- return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, err)
- }
- } else {
- columnPatch := &api.ColumnPatch{
- ID: storedColumn.ID,
- UpdaterId: api.SYSTEM_BOT_ID,
- SyncStatus: &syncStatus,
- LastSuccessfulSyncTs: &ts,
- }
- _, err := s.ColumnService.PatchColumn(context.Background(), columnPatch)
- if err != nil {
- if common.ErrorCode(err) == common.ENOTFOUND {
- return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Column not found: %s", instance.Name, database.Name, upsertedTable.Name, storedColumn.Name)
- }
- return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Failed to update column: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, storedColumn.Name, err)
- }
- }
- }
-
- // Index
- for _, index := range table.IndexList {
- indexFind := &api.IndexFind{
- DatabaseId: &database.ID,
- TableId: &upsertedTable.ID,
- Name: &index.Name,
- Expression: &index.Expression,
- }
- storedIndex, err := s.IndexService.FindIndex(context.Background(), indexFind)
- if err != nil {
- if common.ErrorCode(err) == common.ENOTFOUND {
- indexCreate := &api.IndexCreate{
- CreatorId: api.SYSTEM_BOT_ID,
- DatabaseId: database.ID,
- TableId: upsertedTable.ID,
- Name: index.Name,
- Expression: index.Expression,
- Position: index.Position,
- Type: index.Type,
- Unique: index.Unique,
- Visible: index.Visible,
- Comment: index.Comment,
- }
- if err := createIndex(database, upsertedTable, indexCreate); err != nil {
- return err
- }
- } else {
- return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, err)
- }
- } else {
- indexPatch := &api.IndexPatch{
- ID: storedIndex.ID,
- UpdaterId: api.SYSTEM_BOT_ID,
- SyncStatus: &syncStatus,
- LastSuccessfulSyncTs: &ts,
- }
- _, err := s.IndexService.PatchIndex(context.Background(), indexPatch)
- if err != nil {
- if common.ErrorCode(err) == common.ENOTFOUND {
- return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Index not found: %s", instance.Name, database.Name, upsertedTable.Name, storedIndex.Name)
- }
- return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Failed to update index: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, storedIndex.Name, err)
- }
- }
+ return err
}
}
} else {
- // Case 2
+ // Case 2, only appear in the synced db schema
z, offset := time.Now().Zone()
databaseCreate := &api.DatabaseCreate{
CreatorId: api.SYSTEM_BOT_ID,
@@ -385,94 +351,15 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
for _, table := range schema.TableList {
- // Table
- tableCreate := &api.TableCreate{
- CreatorId: api.SYSTEM_BOT_ID,
- DatabaseId: database.ID,
- Name: table.Name,
- Type: table.Type,
- Engine: table.Engine,
- Collation: table.Collation,
- RowCount: table.RowCount,
- DataSize: table.DataSize,
- IndexSize: table.IndexSize,
- DataFree: table.DataFree,
- CreateOptions: table.CreateOptions,
- Comment: table.Comment,
- }
- upsertedTable, err := createTable(database, tableCreate)
+ err = recreateTableSchema(database, table)
if err != nil {
return err
}
-
- // Column
- for _, column := range table.ColumnList {
- columnFind := &api.ColumnFind{
- DatabaseId: &database.ID,
- TableId: &upsertedTable.ID,
- Name: &column.Name,
- }
- _, err := s.ColumnService.FindColumn(context.Background(), columnFind)
- if err != nil {
- if common.ErrorCode(err) == common.ENOTFOUND {
- columnCreate := &api.ColumnCreate{
- CreatorId: api.SYSTEM_BOT_ID,
- DatabaseId: database.ID,
- TableId: upsertedTable.ID,
- Name: column.Name,
- Position: column.Position,
- Default: column.Default,
- Nullable: column.Nullable,
- Type: column.Type,
- CharacterSet: column.CharacterSet,
- Collation: column.Collation,
- Comment: column.Comment,
- }
- if err := createColumn(database, upsertedTable, columnCreate); err != nil {
- return err
- }
- } else {
- return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, err)
- }
- }
- }
-
- // Index
- for _, index := range table.IndexList {
- indexFind := &api.IndexFind{
- DatabaseId: &database.ID,
- TableId: &upsertedTable.ID,
- Name: &index.Name,
- Expression: &index.Expression,
- }
- _, err := s.IndexService.FindIndex(context.Background(), indexFind)
- if err != nil {
- if common.ErrorCode(err) == common.ENOTFOUND {
- indexCreate := &api.IndexCreate{
- CreatorId: api.SYSTEM_BOT_ID,
- DatabaseId: database.ID,
- TableId: upsertedTable.ID,
- Name: index.Name,
- Expression: index.Expression,
- Position: index.Position,
- Type: index.Type,
- Unique: index.Unique,
- Visible: index.Visible,
- Comment: index.Comment,
- }
- if err := createIndex(database, upsertedTable, indexCreate); err != nil {
- return err
- }
- } else {
- return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, err)
- }
- }
- }
}
}
}
- // Case 3
+ // Case 3, only appear in the bytebase metadata
for _, db := range dbList {
found := false
for _, schema := range schemaList {
diff --git a/store/column.go b/store/column.go
index 0852cde5f7..4f7215dc2c 100644
--- a/store/column.go
+++ b/store/column.go
@@ -121,8 +121,6 @@ func (s *ColumnService) createColumn(ctx context.Context, tx *Tx, create *api.Co
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`+"`default`,"+`
@@ -132,8 +130,8 @@ func (s *ColumnService) createColumn(ctx context.Context, tx *Tx, create *api.Co
collation,
comment
)
- VALUES (?, ?, ?, ?, 'OK', (strftime('%s', 'now')), ?, ?, ?, ?, ?, ?, ?, ?)`+
- "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, sync_status, last_successful_sync_ts, name, position, `default`, `nullable`, `type`, character_set, `collation`, comment"+`
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`+
+ "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, name, position, `default`, `nullable`, `type`, character_set, `collation`, comment"+`
`,
create.CreatorId,
create.CreatorId,
@@ -164,8 +162,6 @@ func (s *ColumnService) createColumn(ctx context.Context, tx *Tx, create *api.Co
&column.UpdatedTs,
&column.DatabaseId,
&column.TableId,
- &column.SyncStatus,
- &column.LastSuccessfulSyncTs,
&column.Name,
&column.Position,
&defaultStr,
@@ -210,8 +206,6 @@ func (s *ColumnService) findColumnList(ctx context.Context, tx *Tx, find *api.Co
updated_ts,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`+"`default`,"+`
@@ -243,8 +237,6 @@ func (s *ColumnService) findColumnList(ctx context.Context, tx *Tx, find *api.Co
&column.UpdatedTs,
&column.DatabaseId,
&column.TableId,
- &column.SyncStatus,
- &column.LastSuccessfulSyncTs,
&column.Name,
&column.Position,
&defaultStr,
@@ -274,12 +266,6 @@ func (s *ColumnService) findColumnList(ctx context.Context, tx *Tx, find *api.Co
func (s *ColumnService) patchColumn(ctx context.Context, tx *Tx, patch *api.ColumnPatch) (*api.Column, error) {
// Build UPDATE clause.
set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterId}
- if v := patch.SyncStatus; v != nil {
- set, args = append(set, "sync_status = ?"), append(args, api.SyncStatus(*v))
- }
- if v := patch.LastSuccessfulSyncTs; v != nil {
- set, args = append(set, "last_successful_sync_ts = ?"), append(args, *v)
- }
args = append(args, patch.ID)
@@ -288,7 +274,7 @@ func (s *ColumnService) patchColumn(ctx context.Context, tx *Tx, patch *api.Colu
UPDATE col
SET `+strings.Join(set, ", ")+`
WHERE id = ?`+
- "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, sync_status, last_successful_sync_ts, name, position, `default`, `nullable`, `type`, character_set, `collation`, comment"+`
+ "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, name, position, `default`, `nullable`, `type`, character_set, `collation`, comment"+`
`,
args...,
)
@@ -308,8 +294,6 @@ func (s *ColumnService) patchColumn(ctx context.Context, tx *Tx, patch *api.Colu
&column.UpdatedTs,
&column.DatabaseId,
&column.TableId,
- &column.SyncStatus,
- &column.LastSuccessfulSyncTs,
&column.Name,
&column.Position,
&defaultStr,
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index 1640da0f6b..4b737434a5 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -419,9 +419,7 @@ CREATE TABLE tbl (
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
updater_id INTEGER NOT NULL REFERENCES principal (id),
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- database_id INTEGER NOT NULL REFERENCES db (id),
- sync_status TEXT NOT NULL CHECK (sync_status IN ('OK', 'NOT_FOUND')),
- last_successful_sync_ts BIGINT NOT NULL,
+ database_id INTEGER NOT NULL REFERENCES db (id) ON DELETE CASCADE,
name TEXT NOT NULL,
`type` TEXT NOT NULL,
`engine` TEXT NOT NULL,
@@ -467,9 +465,7 @@ CREATE TABLE col (
updater_id INTEGER NOT NULL REFERENCES principal (id),
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
database_id INTEGER NOT NULL REFERENCES db (id),
- table_id INTEGER NOT NULL REFERENCES tbl (id),
- sync_status TEXT NOT NULL CHECK (sync_status IN ('OK', 'NOT_FOUND')),
- last_successful_sync_ts BIGINT NOT NULL,
+ table_id INTEGER NOT NULL REFERENCES tbl (id) ON DELETE CASCADE,
name TEXT NOT NULL,
position INTEGER NOT NULL,
`default` TEXT,
@@ -513,9 +509,7 @@ CREATE TABLE idx (
updater_id INTEGER NOT NULL REFERENCES principal (id),
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
database_id INTEGER NOT NULL REFERENCES db (id),
- table_id INTEGER NOT NULL REFERENCES tbl (id),
- sync_status TEXT NOT NULL CHECK (sync_status IN ('OK', 'NOT_FOUND')),
- last_successful_sync_ts BIGINT NOT NULL,
+ table_id INTEGER NOT NULL REFERENCES tbl (id) ON DELETE CASCADE,
name TEXT NOT NULL,
expression TEXT NOT NULL,
position INTEGER NOT NULL,
diff --git a/store/seed/test/10071__tbl.sql b/store/seed/test/10071__tbl.sql
index 3f160d8484..e82752cf2f 100644
--- a/store/seed/test/10071__tbl.sql
+++ b/store/seed/test/10071__tbl.sql
@@ -9,8 +9,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -28,8 +26,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1625075289,
1234,
16384,
0,
@@ -48,8 +44,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -66,8 +60,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1625075289,
1234,
16384,
16384,
@@ -86,8 +78,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -104,8 +94,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624475289,
12234,
65536,
16384,
@@ -124,8 +112,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -142,8 +128,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624475289,
1234,
32768,
4096,
@@ -162,8 +146,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -180,8 +162,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624275289,
1000,
4096,
0,
@@ -200,8 +180,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -218,8 +196,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624575289,
1000,
4096,
1024,
@@ -238,8 +214,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -256,8 +230,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624275289,
1000,
4096,
1024,
@@ -275,8 +247,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -293,8 +263,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624275289,
1000,
8192,
1024,
@@ -312,8 +280,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -330,8 +296,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624275289,
30000,
65536,
4096,
@@ -350,8 +314,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -368,8 +330,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624675289,
100,
4096,
0,
@@ -387,8 +347,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -405,8 +363,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624675289,
300,
4096,
1024,
@@ -424,8 +380,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -442,8 +396,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1624675289,
2000,
65536,
2048,
@@ -462,8 +414,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -480,8 +430,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1622675289,
200,
4096,
1024,
@@ -499,8 +447,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -517,8 +463,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1622675289,
500,
4096,
1024,
@@ -536,8 +480,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -554,8 +496,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1622675289,
4000,
65536,
65536,
@@ -574,8 +514,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -592,8 +530,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1622275289,
200,
4096,
1024,
@@ -611,8 +547,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -629,8 +563,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1622275289,
500,
4096,
1024,
@@ -648,8 +580,6 @@ INSERT INTO
`type`,
ENGINE,
`collation`,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -666,8 +596,6 @@ VALUES
'BASE TABLE',
'InnoDB',
'utf8mb4_general_ci',
- 'OK',
- 1622275289,
7000,
8192,
0,
diff --git a/store/seed/test/10072__col.sql b/store/seed/test/10072__col.sql
index 9dd70d35f5..20538b7af6 100644
--- a/store/seed/test/10072__col.sql
+++ b/store/seed/test/10072__col.sql
@@ -6,8 +6,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -24,8 +22,6 @@ VALUES
101,
7002,
7101,
- 'OK',
- 1625075289,
'col1',
1,
NULL,
@@ -43,8 +39,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -60,8 +54,6 @@ VALUES
101,
7006,
7102,
- 'OK',
- 1625075289,
'col1',
1,
NULL,
@@ -79,8 +71,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -96,8 +86,6 @@ VALUES
101,
7010,
7103,
- 'OK',
- 1625075289,
'col1',
1,
NULL,
@@ -115,8 +103,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -132,8 +118,6 @@ VALUES
101,
7014,
7104,
- 'OK',
- 1625075289,
'col1',
1,
NULL,
@@ -151,8 +135,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -168,8 +150,6 @@ VALUES
101,
7003,
7105,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -186,8 +166,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -203,8 +181,6 @@ VALUES
101,
7003,
7105,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -221,8 +197,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -238,8 +212,6 @@ VALUES
101,
7003,
7105,
- 'OK',
- 1625075289,
'description',
3,
NULL,
@@ -257,8 +229,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -274,8 +244,6 @@ VALUES
101,
7007,
7106,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -292,8 +260,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -309,8 +275,6 @@ VALUES
101,
7007,
7106,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -327,8 +291,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -344,8 +306,6 @@ VALUES
101,
7007,
7106,
- 'OK',
- 1625075289,
'description',
3,
NULL,
@@ -363,8 +323,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -380,8 +338,6 @@ VALUES
101,
7004,
7107,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -398,8 +354,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -415,8 +369,6 @@ VALUES
101,
7004,
7107,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -433,8 +385,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -450,8 +400,6 @@ VALUES
101,
7004,
7107,
- 'OK',
- 1625075289,
'email',
3,
NULL,
@@ -469,8 +417,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -486,8 +432,6 @@ VALUES
101,
7004,
7108,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -504,8 +448,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -521,8 +463,6 @@ VALUES
101,
7004,
7108,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -539,8 +479,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -556,8 +494,6 @@ VALUES
101,
7004,
7108,
- 'OK',
- 1625075289,
'content',
3,
NULL,
@@ -574,8 +510,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -591,8 +525,6 @@ VALUES
101,
7004,
7108,
- 'OK',
- 1625075289,
'author_id',
4,
NULL,
@@ -610,8 +542,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -627,8 +557,6 @@ VALUES
101,
7004,
7109,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -645,8 +573,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -662,8 +588,6 @@ VALUES
101,
7004,
7109,
- 'OK',
- 1625075289,
'content',
2,
NULL,
@@ -680,8 +604,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -697,8 +619,6 @@ VALUES
101,
7004,
7109,
- 'OK',
- 1625075289,
'post_id',
3,
NULL,
@@ -715,8 +635,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -732,8 +650,6 @@ VALUES
101,
7004,
7109,
- 'OK',
- 1625075289,
'author_id',
4,
NULL,
@@ -751,8 +667,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -768,8 +682,6 @@ VALUES
101,
7008,
7110,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -786,8 +698,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -803,8 +713,6 @@ VALUES
101,
7008,
7110,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -821,8 +729,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -838,8 +744,6 @@ VALUES
101,
7008,
7110,
- 'OK',
- 1625075289,
'email',
3,
NULL,
@@ -857,8 +761,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -874,8 +776,6 @@ VALUES
101,
7008,
7111,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -892,8 +792,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -909,8 +807,6 @@ VALUES
101,
7008,
7111,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -927,8 +823,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -944,8 +838,6 @@ VALUES
101,
7008,
7111,
- 'OK',
- 1625075289,
'content',
3,
NULL,
@@ -962,8 +854,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -979,8 +869,6 @@ VALUES
101,
7008,
7111,
- 'OK',
- 1625075289,
'author_id',
4,
NULL,
@@ -998,8 +886,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1015,8 +901,6 @@ VALUES
101,
7008,
7112,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -1033,8 +917,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1050,8 +932,6 @@ VALUES
101,
7008,
7112,
- 'OK',
- 1625075289,
'content',
2,
NULL,
@@ -1068,8 +948,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1085,8 +963,6 @@ VALUES
101,
7008,
7112,
- 'OK',
- 1625075289,
'post_id',
3,
NULL,
@@ -1103,8 +979,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1120,8 +994,6 @@ VALUES
101,
7008,
7112,
- 'OK',
- 1625075289,
'author_id',
4,
NULL,
@@ -1139,8 +1011,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1156,8 +1026,6 @@ VALUES
101,
7012,
7113,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -1174,8 +1042,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1191,8 +1057,6 @@ VALUES
101,
7012,
7113,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -1209,8 +1073,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1226,8 +1088,6 @@ VALUES
101,
7012,
7113,
- 'OK',
- 1625075289,
'email',
3,
NULL,
@@ -1245,8 +1105,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1262,8 +1120,6 @@ VALUES
101,
7012,
7114,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -1280,8 +1136,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1297,8 +1151,6 @@ VALUES
101,
7012,
7114,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -1315,8 +1167,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1332,8 +1182,6 @@ VALUES
101,
7012,
7114,
- 'OK',
- 1625075289,
'content',
3,
NULL,
@@ -1350,8 +1198,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1367,8 +1213,6 @@ VALUES
101,
7012,
7114,
- 'OK',
- 1625075289,
'author_id',
4,
NULL,
@@ -1386,8 +1230,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1403,8 +1245,6 @@ VALUES
101,
7012,
7115,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -1421,8 +1261,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1438,8 +1276,6 @@ VALUES
101,
7012,
7115,
- 'OK',
- 1625075289,
'content',
2,
NULL,
@@ -1456,8 +1292,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1473,8 +1307,6 @@ VALUES
101,
7012,
7115,
- 'OK',
- 1625075289,
'post_id',
3,
NULL,
@@ -1491,8 +1323,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1508,8 +1338,6 @@ VALUES
101,
7012,
7115,
- 'OK',
- 1625075289,
'author_id',
4,
NULL,
@@ -1527,8 +1355,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1544,8 +1370,6 @@ VALUES
101,
7016,
7116,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -1562,8 +1386,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1579,8 +1401,6 @@ VALUES
101,
7016,
7116,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -1597,8 +1417,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1614,8 +1432,6 @@ VALUES
101,
7016,
7116,
- 'OK',
- 1625075289,
'email',
3,
NULL,
@@ -1633,8 +1449,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1650,8 +1464,6 @@ VALUES
101,
7016,
7117,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -1668,8 +1480,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1685,8 +1495,6 @@ VALUES
101,
7016,
7117,
- 'OK',
- 1625075289,
'name',
2,
NULL,
@@ -1703,8 +1511,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1720,8 +1526,6 @@ VALUES
101,
7016,
7117,
- 'OK',
- 1625075289,
'content',
3,
NULL,
@@ -1738,8 +1542,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1755,8 +1557,6 @@ VALUES
101,
7016,
7117,
- 'OK',
- 1625075289,
'author_id',
4,
NULL,
@@ -1774,8 +1574,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1791,8 +1589,6 @@ VALUES
101,
7016,
7118,
- 'OK',
- 1625075289,
'id',
1,
NULL,
@@ -1809,8 +1605,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1826,8 +1620,6 @@ VALUES
101,
7016,
7118,
- 'OK',
- 1625075289,
'content',
2,
NULL,
@@ -1844,8 +1636,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1861,8 +1651,6 @@ VALUES
101,
7016,
7118,
- 'OK',
- 1625075289,
'post_id',
3,
NULL,
@@ -1879,8 +1667,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
position,
`default`,
@@ -1896,8 +1682,6 @@ VALUES
101,
7016,
7118,
- 'OK',
- 1625075289,
'author_id',
4,
NULL,
diff --git a/store/seed/test/10073__idx.sql b/store/seed/test/10073__idx.sql
index 07fe2081f6..14e8d78083 100644
--- a/store/seed/test/10073__idx.sql
+++ b/store/seed/test/10073__idx.sql
@@ -6,8 +6,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -23,8 +21,6 @@ VALUES
101,
7002,
7101,
- 'OK',
- 1625075289,
'idx_col1',
'col1',
1,
@@ -41,8 +37,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -57,8 +51,6 @@ VALUES
101,
7006,
7102,
- 'OK',
- 1625075289,
'idx_col1',
'col1',
1,
@@ -75,8 +67,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -91,8 +81,6 @@ VALUES
101,
7010,
7103,
- 'OK',
- 1625075289,
'idx_col1',
'col1',
1,
@@ -109,8 +97,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -125,8 +111,6 @@ VALUES
101,
7014,
7104,
- 'OK',
- 1625075289,
'idx_col1',
'col1',
1,
@@ -143,8 +127,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -159,8 +141,6 @@ VALUES
101,
7003,
7105,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -177,8 +157,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -193,8 +171,6 @@ VALUES
101,
7007,
7106,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -211,8 +187,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -227,8 +201,6 @@ VALUES
101,
7004,
7107,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -245,8 +217,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -261,8 +231,6 @@ VALUES
101,
7004,
7108,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -279,8 +247,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -295,8 +261,6 @@ VALUES
101,
7004,
7109,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -313,8 +277,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -329,8 +291,6 @@ VALUES
101,
7008,
7110,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -347,8 +307,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -363,8 +321,6 @@ VALUES
101,
7008,
7111,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -381,8 +337,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -397,8 +351,6 @@ VALUES
101,
7008,
7112,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -415,8 +367,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -431,8 +381,6 @@ VALUES
101,
7012,
7113,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -449,8 +397,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -465,8 +411,6 @@ VALUES
101,
7012,
7114,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -483,8 +427,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -499,8 +441,6 @@ VALUES
101,
7012,
7115,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -517,8 +457,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -533,8 +471,6 @@ VALUES
101,
7016,
7116,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -551,8 +487,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -567,8 +501,6 @@ VALUES
101,
7016,
7117,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
@@ -585,8 +517,6 @@ INSERT INTO
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -601,8 +531,6 @@ VALUES
101,
7016,
7118,
- 'OK',
- 1625075289,
'PRIMARY',
'id',
1,
diff --git a/store/table.go b/store/table.go
index c06498a299..30e84765b3 100644
--- a/store/table.go
+++ b/store/table.go
@@ -103,6 +103,27 @@ func (s *TableService) PatchTable(ctx context.Context, patch *api.TablePatch) (*
return table, nil
}
+// DeleteTable deletes an existing table by ID.
+// Returns ENOTFOUND if table does not exist.
+func (s *TableService) DeleteTable(ctx context.Context, delete *api.TableDelete) error {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return FormatError(err)
+ }
+ defer tx.Rollback()
+
+ err = deleteTable(ctx, tx, delete)
+ if err != nil {
+ return FormatError(err)
+ }
+
+ if err := tx.Commit(); err != nil {
+ return FormatError(err)
+ }
+
+ return nil
+}
+
// createTable creates a new table.
func (s *TableService) createTable(ctx context.Context, tx *Tx, create *api.TableCreate) (*api.Table, error) {
// Insert row into table.
@@ -115,8 +136,6 @@ func (s *TableService) createTable(ctx context.Context, tx *Tx, create *api.Tabl
`+"`type`,"+`
engine,
collation,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -124,8 +143,8 @@ func (s *TableService) createTable(ctx context.Context, tx *Tx, create *api.Tabl
create_options,
comment
)
- VALUES (?, ?, ?, ?, ?, ?, ?, 'OK', (strftime('%s', 'now')), ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, name, `+"`type`, engine, collation, sync_status, last_successful_sync_ts, row_count, data_size, index_size, data_free, create_options, comment"+`
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, name, `+"`type`, engine, collation, row_count, data_size, index_size, data_free, create_options, comment"+`
`,
create.CreatorId,
create.CreatorId,
@@ -160,8 +179,6 @@ func (s *TableService) createTable(ctx context.Context, tx *Tx, create *api.Tabl
&table.Type,
&table.Engine,
&table.Collation,
- &table.SyncStatus,
- &table.LastSuccessfulSyncTs,
&table.RowCount,
&table.DataSize,
&table.IndexSize,
@@ -200,8 +217,6 @@ func (s *TableService) findTableList(ctx context.Context, tx *Tx, find *api.Tabl
`+"`type`,"+`
engine,
collation,
- sync_status,
- last_successful_sync_ts,
row_count,
data_size,
index_size,
@@ -232,8 +247,6 @@ func (s *TableService) findTableList(ctx context.Context, tx *Tx, find *api.Tabl
&table.Type,
&table.Engine,
&table.Collation,
- &table.SyncStatus,
- &table.LastSuccessfulSyncTs,
&table.RowCount,
&table.DataSize,
&table.IndexSize,
@@ -257,12 +270,6 @@ func (s *TableService) findTableList(ctx context.Context, tx *Tx, find *api.Tabl
func (s *TableService) patchTable(ctx context.Context, tx *Tx, patch *api.TablePatch) (*api.Table, error) {
// Build UPDATE clause.
set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterId}
- if v := patch.SyncStatus; v != nil {
- set, args = append(set, "sync_status = ?"), append(args, api.SyncStatus(*v))
- }
- if v := patch.LastSuccessfulSyncTs; v != nil {
- set, args = append(set, "last_successful_sync_ts = ?"), append(args, *v)
- }
args = append(args, patch.ID)
@@ -271,7 +278,7 @@ func (s *TableService) patchTable(ctx context.Context, tx *Tx, patch *api.TableP
UPDATE tbl
SET `+strings.Join(set, ", ")+`
WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, name, `+"`type`, engine, collation, sync_status, last_successful_sync_ts, row_count, data_size, index_size, data_free, create_options, comment"+`
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, name, `+"`type`, engine, collation, row_count, data_size, index_size, data_free, create_options, comment"+`
`,
args...,
)
@@ -293,8 +300,6 @@ func (s *TableService) patchTable(ctx context.Context, tx *Tx, patch *api.TableP
&table.Type,
&table.Engine,
&table.Collation,
- &table.SyncStatus,
- &table.LastSuccessfulSyncTs,
&table.RowCount,
&table.DataSize,
&table.IndexSize,
@@ -309,3 +314,14 @@ func (s *TableService) patchTable(ctx context.Context, tx *Tx, patch *api.TableP
return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("table ID not found: %d", patch.ID)}
}
+
+// deleteTable permanently deletes tables from a database.
+func deleteTable(ctx context.Context, tx *Tx, delete *api.TableDelete) error {
+ // Remove row from database.
+ _, err := tx.ExecContext(ctx, `DELETE FROM tbl WHERE database_id = ?`, delete.DatabaseId)
+ if err != nil {
+ return FormatError(err)
+ }
+
+ return nil
+}
diff --git a/store/table_index.go b/store/table_index.go
index e9e7d18baa..791d8d6308 100644
--- a/store/table_index.go
+++ b/store/table_index.go
@@ -112,8 +112,6 @@ func (s *IndexService) createIndex(ctx context.Context, tx *Tx, create *api.Inde
updater_id,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -122,8 +120,8 @@ func (s *IndexService) createIndex(ctx context.Context, tx *Tx, create *api.Inde
visible,
comment
)
- VALUES (?, ?, ?, ?, 'OK', (strftime('%s', 'now')), ?, ?, ?, ?, ?, ?, ?)`+
- "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, sync_status, last_successful_sync_ts, name, expression, position, `type`, `unique`, visible, comment"+`
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`+
+ "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, name, expression, position, `type`, `unique`, visible, comment"+`
`,
create.CreatorId,
create.CreatorId,
@@ -153,8 +151,6 @@ func (s *IndexService) createIndex(ctx context.Context, tx *Tx, create *api.Inde
&index.UpdatedTs,
&index.DatabaseId,
&index.TableId,
- &index.SyncStatus,
- &index.LastSuccessfulSyncTs,
&index.Name,
&index.Expression,
&index.Position,
@@ -197,8 +193,6 @@ func (s *IndexService) findIndexList(ctx context.Context, tx *Tx, find *api.Inde
updated_ts,
database_id,
table_id,
- sync_status,
- last_successful_sync_ts,
name,
expression,
position,
@@ -228,8 +222,6 @@ func (s *IndexService) findIndexList(ctx context.Context, tx *Tx, find *api.Inde
&index.UpdatedTs,
&index.DatabaseId,
&index.TableId,
- &index.SyncStatus,
- &index.LastSuccessfulSyncTs,
&index.Name,
&index.Expression,
&index.Position,
@@ -254,12 +246,6 @@ func (s *IndexService) findIndexList(ctx context.Context, tx *Tx, find *api.Inde
func (s *IndexService) patchIndex(ctx context.Context, tx *Tx, patch *api.IndexPatch) (*api.Index, error) {
// Build UPDATE clause.
set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterId}
- if v := patch.SyncStatus; v != nil {
- set, args = append(set, "sync_status = ?"), append(args, api.SyncStatus(*v))
- }
- if v := patch.LastSuccessfulSyncTs; v != nil {
- set, args = append(set, "last_successful_sync_ts = ?"), append(args, *v)
- }
args = append(args, patch.ID)
@@ -268,7 +254,7 @@ func (s *IndexService) patchIndex(ctx context.Context, tx *Tx, patch *api.IndexP
UPDATE idx
SET `+strings.Join(set, ", ")+`
WHERE id = ?`+
- "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, sync_status, last_successful_sync_ts, name, expression, position, `type`, `unique`, visible, comment"+`
+ "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, name, expression, position, `type`, `unique`, visible, comment"+`
`,
args...,
)
@@ -287,8 +273,6 @@ func (s *IndexService) patchIndex(ctx context.Context, tx *Tx, patch *api.IndexP
&index.UpdatedTs,
&index.DatabaseId,
&index.TableId,
- &index.SyncStatus,
- &index.LastSuccessfulSyncTs,
&index.Name,
&index.Expression,
&index.Position,