Skip to content

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

Store column info and expose it on the table detail page

天舟fb84131b9826
diff --git a/api/column.go b/api/column.go
new file mode 100644
index 0000000000..ca41a5b4b2
--- /dev/null
+++ b/api/column.go
@@ -0,0 +1,90 @@
+package api
+
+import (
+ "context"
+ "encoding/json"
+)
+
+type Column struct {
+ ID int `jsonapi:"primary,column"`
+
+ // Standard fields
+ CreatorId int
+ CreatedTs int64 `json:"createdTs"`
+ UpdaterId int
+ UpdatedTs int64 `json:"updatedTs"`
+
+ // Related fields
+ DatabaseId int
+ 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"`
+}
+
+type ColumnCreate struct {
+ // Standard fields
+ // Value is assigned from the jwt subject field passed by the client.
+ CreatorId int
+
+ // Related fields
+ DatabaseId int
+ TableId int
+
+ // Domain specific fields
+ Name string
+ Position int
+ Default *string
+ Nullable bool
+ Type string
+ CharacterSet string
+ Collation string
+ Comment string
+}
+
+type ColumnFind struct {
+ ID *int
+
+ // Related fields
+ DatabaseId *int
+ TableId *int
+
+ // Domain specific fields
+ Name *string
+}
+
+func (find *ColumnFind) String() string {
+ str, err := json.Marshal(*find)
+ if err != nil {
+ return err.Error()
+ }
+ return string(str)
+}
+
+type ColumnPatch struct {
+ ID int
+
+ // 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 {
+ CreateColumn(ctx context.Context, create *ColumnCreate) (*Column, error)
+ FindColumnList(ctx context.Context, find *ColumnFind) ([]*Column, error)
+ FindColumn(ctx context.Context, find *ColumnFind) (*Column, error)
+ PatchColumn(ctx context.Context, patch *ColumnPatch) (*Column, error)
+}
diff --git a/api/table.go b/api/table.go
index 12668338ef..f60d7ed222 100644
--- a/api/table.go
+++ b/api/table.go
@@ -33,6 +33,7 @@ type Table struct {
DataFree int64 `jsonapi:"attr,dataFree"`
CreateOptions string `jsonapi:"attr,createOptions"`
Comment string `jsonapi:"attr,comment"`
+ ColumnList []*Column `jsonapi:"attr,columnList"`
}
type TableCreate struct {
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index f1bab11f0d..2bf2e5ac65 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -262,6 +262,7 @@ func (m *main) Run() error {
server.DatabaseService = store.NewDatabaseService(m.l, db, server.CacheService)
server.InstanceService = store.NewInstanceService(m.l, db, server.CacheService, server.DatabaseService, server.DataSourceService)
server.TableService = store.NewTableService(m.l, db)
+ server.ColumnService = store.NewColumnService(m.l, db)
server.IssueService = store.NewIssueService(m.l, db, server.CacheService)
server.IssueSubscriberService = store.NewIssueSubscriberService(m.l, db)
server.PipelineService = store.NewPipelineService(m.l, db, server.CacheService)
diff --git a/db/driver.go b/db/driver.go
index d985f4a4a8..1f8abf1f93 100644
--- a/db/driver.go
+++ b/db/driver.go
@@ -25,6 +25,17 @@ func (e Type) String() string {
return "UNKNOWN"
}
+type DBColumn struct {
+ Name string
+ Position int
+ Default *string
+ Nullable bool
+ Type string
+ CharacterSet string
+ Collation string
+ Comment string
+}
+
type DBTable struct {
Name string
CreatedTs int64
@@ -38,6 +49,7 @@ type DBTable struct {
DataFree int64
CreateOptions string
Comment string
+ ColumnList []DBColumn
}
type DBSchema struct {
diff --git a/db/mysql.go b/db/mysql.go
index 880697c1bd..4fb09cddfc 100644
--- a/db/mysql.go
+++ b/db/mysql.go
@@ -71,6 +71,65 @@ func (driver *MySQLDriver) SyncSchema(ctx context.Context) ([]*DBSchema, error)
"'sys'",
}
+ // Query column info
+ columnWhere := fmt.Sprintf("TABLE_SCHEMA NOT IN (%s)", strings.Join(excludedDatabaseList, ", "))
+ columnRows, err := driver.db.QueryContext(ctx, `
+ SELECT
+ TABLE_SCHEMA,
+ TABLE_NAME,
+ IFNULL(COLUMN_NAME, ''),
+ ORDINAL_POSITION,
+ COLUMN_DEFAULT,
+ IS_NULLABLE,
+ COLUMN_TYPE,
+ IFNULL(CHARACTER_SET_NAME, ''),
+ IFNULL(COLLATION_NAME, ''),
+ COLUMN_COMMENT
+ FROM information_schema.COLUMNS
+ WHERE `+columnWhere,
+ )
+ if err != nil {
+ return nil, err
+ }
+
+ // dbName.tableName -> columnList map
+ columnMap := make(map[string][]DBColumn)
+ for columnRows.Next() {
+ var dbName string
+ var tableName string
+ var nullable string
+ var defaultStr sql.NullString
+ var column DBColumn
+ if err := columnRows.Scan(
+ &dbName,
+ &tableName,
+ &column.Name,
+ &column.Position,
+ &defaultStr,
+ &nullable,
+ &column.Type,
+ &column.CharacterSet,
+ &column.Collation,
+ &column.Comment,
+ ); err != nil {
+ return nil, err
+ }
+
+ if defaultStr.Valid {
+ column.Default = &defaultStr.String
+ }
+
+ key := fmt.Sprintf("%s.%s", dbName, tableName)
+ tableList, ok := columnMap[key]
+ if ok {
+ columnMap[key] = append(tableList, column)
+ } else {
+ list := make([]DBColumn, 0)
+ columnMap[key] = append(list, column)
+ }
+ }
+ columnRows.Close()
+
// Query table info
tableWhere := fmt.Sprintf("TABLE_SCHEMA NOT IN (%s)", strings.Join(excludedDatabaseList, ", "))
tableRows, err := driver.db.QueryContext(ctx, `
@@ -118,6 +177,9 @@ func (driver *MySQLDriver) SyncSchema(ctx context.Context) ([]*DBSchema, error)
return nil, err
}
+ key := fmt.Sprintf("%s.%s", dbName, table.Name)
+ table.ColumnList = columnMap[key]
+
tableList, ok := tableMap[dbName]
if ok {
tableMap[dbName] = append(tableList, table)
diff --git a/frontend/src/components/ColumnTable.vue b/frontend/src/components/ColumnTable.vue
new file mode 100644
index 0000000000..3c810e7dac
--- /dev/null
+++ b/frontend/src/components/ColumnTable.vue
@@ -0,0 +1,91 @@
+<template>
+ <BBTable
+ :columnList="COLUMN_LIST"
+ :dataSource="columnList"
+ :showHeader="true"
+ :leftBordered="true"
+ :rightBordered="true"
+ >
+ <template v-slot:body="{ rowData: column }">
+ <BBTableCell :leftPadding="4" class="w-16">
+ {{ column.name }}
+ </BBTableCell>
+ <BBTableCell class="w-8">
+ {{ column.type }}
+ </BBTableCell>
+ <BBTableCell class="w-8">
+ {{ column.default }}
+ </BBTableCell>
+ <BBTableCell class="w-8">
+ {{ column.nullable }}
+ </BBTableCell>
+ <BBTableCell class="w-8">
+ {{ column.characterSet }}
+ </BBTableCell>
+ <BBTableCell class="w-8">
+ {{ column.collation }}
+ </BBTableCell>
+ <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>
+
+<script lang="ts">
+import { PropType } from "vue";
+import { BBTableColumn } from "../bbkit/types";
+import { Column } from "../types";
+
+const COLUMN_LIST: BBTableColumn[] = [
+ {
+ title: "Name",
+ },
+ {
+ title: "Type",
+ },
+ {
+ title: "Default",
+ },
+ {
+ title: "Nullable",
+ },
+ {
+ title: "Character set",
+ },
+ {
+ title: "Collation",
+ },
+ {
+ title: "Comment",
+ },
+ {
+ title: "Sync status",
+ },
+ {
+ title: "Last successful sync",
+ },
+];
+
+export default {
+ name: "TableTable",
+ components: {},
+ props: {
+ columnList: {
+ required: true,
+ type: Object as PropType<Column[]>,
+ },
+ },
+ setup(props, ctx) {
+ return {
+ COLUMN_LIST,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/types/column.ts b/frontend/src/types/column.ts
new file mode 100644
index 0000000000..d8bc035a58
--- /dev/null
+++ b/frontend/src/types/column.ts
@@ -0,0 +1,31 @@
+import { ColumnId, DatabaseId, TableId } from "./id";
+
+// Similar to DatabaseSyncStatus, see comment
+export type ColumnSyncStatus = "OK" | "NOT_FOUND";
+
+// Column
+export type Column = {
+ id: ColumnId;
+
+ // Related fields
+ databaseId: DatabaseId;
+ tableId: TableId;
+
+ // Standard fields
+ creatorId: number;
+ createdTs: number;
+ updaterId: number;
+ updatedTs: number;
+
+ // Domain specific fields
+ syncStatus: ColumnSyncStatus;
+ lastSuccessfulSyncTs: number;
+ name: string;
+ position: number;
+ default: string;
+ nullable: boolean;
+ type: string;
+ characterSet: string;
+ collation: string;
+ comment: string;
+};
diff --git a/frontend/src/types/database.ts b/frontend/src/types/database.ts
index 0de72cb58e..8b06b598cf 100644
--- a/frontend/src/types/database.ts
+++ b/frontend/src/types/database.ts
@@ -2,11 +2,11 @@
// in the "database" object.
// Physically, a database belongs to an instance. Logically, it belongs to a project.
+import { DataSource } from "./dataSource";
import { DatabaseId, InstanceId, IssueId, ProjectId } from "./id";
import { Instance } from "./instance";
import { Principal } from "./principal";
import { Project } from "./project";
-import { DataSource } from "./dataSource";
// "OK" means we find the database with the same name.
// "NOT_FOUND" means no matching database name found, this ususally means someone changes the underlying db name without Bytebase knowledge.
@@ -27,11 +27,11 @@ export type Database = {
updatedTs: number;
// Domain specific fields
+ syncStatus: DatabaseSyncStatus;
+ lastSuccessfulSyncTs: number;
name: string;
characterSet: string;
collation: string;
- syncStatus: DatabaseSyncStatus;
- lastSuccessfulSyncTs: number;
};
export type DatabaseCreate = {
diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.ts
index 8091b70e15..a35af1d4b4 100644
--- a/frontend/src/types/id.ts
+++ b/frontend/src/types/id.ts
@@ -37,6 +37,8 @@ export type DatabaseId = IdType;
export type TableId = IdType;
+export type ColumnId = IdType;
+
export type VCSId = IdType;
export type RepositoryId = IdType;
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 4a06af5837..a5a2988648 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -1,28 +1,27 @@
+export * from "./activity";
+export * from "./actuator";
+export * from "./auth";
+export * from "./bookmark";
+export * from "./column";
export * from "./common";
-export * from "./id";
+export * from "./database";
+export * from "./dataSource";
export * from "./environment";
-export * from "./member";
-export * from "./principal";
-export * from "./project";
+export * from "./id";
+export * from "./instance";
export * from "./issue";
export * from "./issueSubscriber";
-export * from "./pipeline";
-export * from "./instance";
-export * from "./database";
-export * from "./table";
-export * from "./dataSource";
-export * from "./sql";
-export * from "./bookmark";
-export * from "./activity";
+export * from "./jsonapi";
+export * from "./member";
export * from "./message";
-export * from "./vcs";
-export * from "./repository";
-export * from "./auth";
export * from "./notification";
+export * from "./oauth";
+export * from "./pipeline";
export * from "./plan";
+export * from "./principal";
+export * from "./project";
+export * from "./repository";
+export * from "./sql";
export * from "./store";
-
-export * from "./actuator";
-
-export * from "./oauth";
-export * from "./jsonapi";
+export * from "./table";
+export * from "./vcs";
diff --git a/frontend/src/types/table.ts b/frontend/src/types/table.ts
index c8e4b8f392..ec6dc523c5 100644
--- a/frontend/src/types/table.ts
+++ b/frontend/src/types/table.ts
@@ -1,3 +1,4 @@
+import { Column } from "./column";
import { Database } from "./database";
import { TableId } from "./id";
import { Principal } from "./principal";
@@ -21,16 +22,17 @@ export type Table = {
updatedTs: number;
// Domain specific fields
+ syncStatus: TableSyncStatus;
+ lastSuccessfulSyncTs: number;
name: string;
type: TableType;
engine: TableEngineType;
collation: string;
- syncStatus: TableSyncStatus;
- lastSuccessfulSyncTs: number;
rowCount: number;
dataSize: number;
indexSize: number;
dataFree: number;
createOptions: string;
comment: string;
+ columnList: Column[];
};
diff --git a/frontend/src/views/TableDetail.vue b/frontend/src/views/TableDetail.vue
index 5a33d9e508..013eb6cff2 100644
--- a/frontend/src/views/TableDetail.vue
+++ b/frontend/src/views/TableDetail.vue
@@ -167,6 +167,10 @@
</dl>
</div>
</div>
+
+ <div class="mt-6 px-6">
+ <ColumnTable :columnList="table.columnList" />
+ </div>
</main>
</div>
</template>
@@ -174,6 +178,7 @@
<script lang="ts">
import { computed } from "@vue/runtime-core";
import { useStore } from "vuex";
+import ColumnTable from "../components/ColumnTable.vue";
import { bytesToString, idFromSlug } from "../utils";
export default {
@@ -188,7 +193,7 @@ export default {
type: String,
},
},
- components: {},
+ components: { ColumnTable },
setup(props, ctx) {
const store = useStore();
diff --git a/server/database.go b/server/database.go
index ef69484bab..4e4121f6c1 100644
--- a/server/database.go
+++ b/server/database.go
@@ -169,6 +169,14 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
for _, table := range tableList {
table.Database = database
+ columnFind := &api.ColumnFind{
+ DatabaseId: &id,
+ TableId: &table.ID,
+ }
+ table.ColumnList, err = s.ColumnService.FindColumnList(context.Background(), columnFind)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch colmun list for database id: %d, table name: %s", id, table.Name)).SetInternal(err)
+ }
}
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
@@ -207,6 +215,15 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
table.Database = database
+ columnFind := &api.ColumnFind{
+ DatabaseId: &id,
+ TableId: &table.ID,
+ }
+ table.ColumnList, err = s.ColumnService.FindColumnList(context.Background(), columnFind)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch colmun list for database id: %d, table name: %s", id, tableName)).SetInternal(err)
+ }
+
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := jsonapi.MarshalPayload(c.Response().Writer, table); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal fetch table response: %v", id)).SetInternal(err)
diff --git a/server/server.go b/server/server.go
index 4abde07602..b6f0b662e4 100644
--- a/server/server.go
+++ b/server/server.go
@@ -32,6 +32,7 @@ type Server struct {
InstanceService api.InstanceService
DatabaseService api.DatabaseService
TableService api.TableService
+ ColumnService api.ColumnService
DataSourceService api.DataSourceService
IssueService api.IssueService
IssueSubscriberService api.IssueSubscriberService
diff --git a/server/sql.go b/server/sql.go
index 5482eb2e55..af3ca09772 100644
--- a/server/sql.go
+++ b/server/sql.go
@@ -106,13 +106,24 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
if err != nil {
resultSet.Error = err.Error()
} else {
- var createTable = func(database *api.Database, tableCreate *api.TableCreate) error {
- _, err := s.TableService.CreateTable(context.Background(), tableCreate)
+ var createTable = func(database *api.Database, tableCreate *api.TableCreate) (*api.Table, error) {
+ createTable, err := s.TableService.CreateTable(context.Background(), tableCreate)
if err != nil {
if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
- return fmt.Errorf("failed to sync table for instance: %s, database: %s. Table name already exists: %s", instance.Name, database.Name, tableCreate.Name)
+ return nil, fmt.Errorf("failed to sync table for instance: %s, database: %s. Table name already exists: %s", instance.Name, database.Name, tableCreate.Name)
}
- return fmt.Errorf("failed to sync database for instance: %s, database: %s. Failed to import new table: %s. Error %w", instance.Name, database.Name, tableCreate.Name, err)
+ return nil, fmt.Errorf("failed to sync table for instance: %s, database: %s. Failed to import new table: %s. Error %w", instance.Name, database.Name, tableCreate.Name, err)
+ }
+ return createTable, nil
+ }
+
+ var createColumn = func(database *api.Database, table *api.Table, columnCreate *api.ColumnCreate) error {
+ _, err := s.ColumnService.CreateColumn(context.Background(), columnCreate)
+ if err != nil {
+ if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Column name already exists: %s", instance.Name, database.Name, table.Name, columnCreate.Name)
+ }
+ return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Failed to import new column: %s. Error %w", instance.Name, database.Name, table.Name, columnCreate.Name, err)
}
return nil
}
@@ -168,6 +179,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
Name: &table.Name,
}
storedTable, err := s.TableService.FindTable(context.Background(), tableFind)
+ var upsertedTable *api.Table
if err != nil {
if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
tableCreate := &api.TableCreate{
@@ -184,7 +196,8 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
CreateOptions: table.CreateOptions,
Comment: table.Comment,
}
- if err := createTable(database, tableCreate); err != nil {
+ upsertedTable, err = createTable(database, tableCreate)
+ if err != nil {
return err
}
} else {
@@ -197,7 +210,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
SyncStatus: &syncStatus,
LastSuccessfulSyncTs: &ts,
}
- _, err := s.TableService.PatchTable(context.Background(), tablePatch)
+ upsertedTable, err = s.TableService.PatchTable(context.Background(), tablePatch)
if err != nil {
if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
return fmt.Errorf("failed to sync table for instance: %s, database: %s. Table not found: %s", instance.Name, database.Name, storedTable.Name)
@@ -205,6 +218,51 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
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)
}
}
+
+ 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 bytebase.ErrorCode(err) == bytebase.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 bytebase.ErrorCode(err) == bytebase.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)
+ }
+ }
+ }
}
} else {
// Case 2
@@ -239,9 +297,41 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
CreateOptions: table.CreateOptions,
Comment: table.Comment,
}
- if err := createTable(database, tableCreate); err != nil {
+ upsertedTable, err := createTable(database, tableCreate)
+ if err != nil {
return err
}
+
+ 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 bytebase.ErrorCode(err) == bytebase.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)
+ }
+ }
+ }
}
}
}
diff --git a/store/column.go b/store/column.go
new file mode 100644
index 0000000000..c240b677b5
--- /dev/null
+++ b/store/column.go
@@ -0,0 +1,333 @@
+package store
+
+import (
+ "context"
+ "database/sql"
+ "fmt"
+ "strings"
+
+ "github.com/bytebase/bytebase"
+ "github.com/bytebase/bytebase/api"
+ "go.uber.org/zap"
+)
+
+var (
+ _ api.ColumnService = (*ColumnService)(nil)
+)
+
+// ColumnService represents a service for managing column.
+type ColumnService struct {
+ l *zap.Logger
+ db *DB
+}
+
+// NewColumnService returns a new instance of ColumnService.
+func NewColumnService(logger *zap.Logger, db *DB) *ColumnService {
+ return &ColumnService{l: logger, db: db}
+}
+
+// CreateColumn creates a new column.
+func (s *ColumnService) CreateColumn(ctx context.Context, create *api.ColumnCreate) (*api.Column, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ column, err := s.createColumn(ctx, tx, create)
+ if err != nil {
+ return nil, err
+ }
+
+ if err := tx.Commit(); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return column, nil
+}
+
+// FindColumnList retrieves a list of columns based on find.
+func (s *ColumnService) FindColumnList(ctx context.Context, find *api.ColumnFind) ([]*api.Column, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ list, err := s.findColumnList(ctx, tx, find)
+ if err != nil {
+ return []*api.Column{}, err
+ }
+
+ return list, nil
+}
+
+// FindColumn retrieves a single column based on find.
+// Returns ENOTFOUND if no matching record.
+// Returns ECONFLICT if finding more than 1 matching records.
+func (s *ColumnService) FindColumn(ctx context.Context, find *api.ColumnFind) (*api.Column, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ list, err := s.findColumnList(ctx, tx, find)
+ if err != nil {
+ return nil, err
+ } else if len(list) == 0 {
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("column not found: %+v", find)}
+ } else if len(list) > 1 {
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d columns with filter %+v, expect 1", len(list), find)}
+ }
+ return list[0], nil
+}
+
+// PatchColumn updates an existing column by ID.
+// Returns ENOTFOUND if column does not exist.
+func (s *ColumnService) PatchColumn(ctx context.Context, patch *api.ColumnPatch) (*api.Column, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ column, err := s.patchColumn(ctx, tx, patch)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+
+ if err := tx.Commit(); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return column, nil
+}
+
+// createColumn creates a new column.
+func (s *ColumnService) createColumn(ctx context.Context, tx *Tx, create *api.ColumnCreate) (*api.Column, error) {
+ defaultStr := sql.NullString{}
+ if create.Default != nil {
+ defaultStr = sql.NullString{
+ String: *create.Default,
+ Valid: true,
+ }
+ }
+
+ // Insert row into column.
+ row, err := tx.QueryContext(ctx, `
+ INSERT INTO col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `+"`default`,"+`
+ `+"`nullable`,"+`
+ `+"`type`,"+`
+ character_set,
+ 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"+`
+ `,
+ create.CreatorId,
+ create.CreatorId,
+ create.DatabaseId,
+ create.TableId,
+ create.Name,
+ create.Position,
+ defaultStr,
+ create.Nullable,
+ create.Type,
+ create.CharacterSet,
+ create.Collation,
+ create.Comment,
+ )
+
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer row.Close()
+
+ row.Next()
+ var column api.Column
+ if err := row.Scan(
+ &column.ID,
+ &column.CreatorId,
+ &column.CreatedTs,
+ &column.UpdaterId,
+ &column.UpdatedTs,
+ &column.DatabaseId,
+ &column.TableId,
+ &column.SyncStatus,
+ &column.LastSuccessfulSyncTs,
+ &column.Name,
+ &column.Position,
+ &defaultStr,
+ &column.Nullable,
+ &column.Type,
+ &column.CharacterSet,
+ &column.Collation,
+ &column.Comment,
+ ); err != nil {
+ return nil, FormatError(err)
+ }
+
+ if defaultStr.Valid {
+ column.Default = &defaultStr.String
+ }
+
+ return &column, nil
+}
+
+func (s *ColumnService) findColumnList(ctx context.Context, tx *Tx, find *api.ColumnFind) (_ []*api.Column, err error) {
+ // Build WHERE clause.
+ where, args := []string{"1 = 1"}, []interface{}{}
+ if v := find.ID; v != nil {
+ where, args = append(where, "id = ?"), append(args, *v)
+ }
+ if v := find.DatabaseId; v != nil {
+ where, args = append(where, "database_id = ?"), append(args, *v)
+ }
+ if v := find.TableId; v != nil {
+ where, args = append(where, "table_id = ?"), append(args, *v)
+ }
+ if v := find.Name; v != nil {
+ where, args = append(where, "name = ?"), append(args, *v)
+ }
+
+ rows, err := tx.QueryContext(ctx, `
+ SELECT
+ 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
+ FROM col
+ WHERE `+strings.Join(where, " AND ")+`
+ ORDER BY database_id, table_id, position ASC`,
+ args...,
+ )
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer rows.Close()
+
+ // Iterate over result set and deserialize rows into list.
+ list := make([]*api.Column, 0)
+ for rows.Next() {
+ var column api.Column
+ defaultStr := sql.NullString{}
+ if err := rows.Scan(
+ &column.ID,
+ &column.CreatorId,
+ &column.CreatedTs,
+ &column.UpdaterId,
+ &column.UpdatedTs,
+ &column.DatabaseId,
+ &column.TableId,
+ &column.SyncStatus,
+ &column.LastSuccessfulSyncTs,
+ &column.Name,
+ &column.Position,
+ &defaultStr,
+ &column.Nullable,
+ &column.Type,
+ &column.CharacterSet,
+ &column.Collation,
+ &column.Comment,
+ ); err != nil {
+ return nil, FormatError(err)
+ }
+
+ if defaultStr.Valid {
+ column.Default = &defaultStr.String
+ }
+
+ list = append(list, &column)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return list, nil
+}
+
+// patchColumn updates a column by ID. Returns the new state of the column after update.
+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)
+
+ // Execute update query with RETURNING.
+ row, err := tx.QueryContext(ctx, `
+ 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"+`
+ `,
+ args...,
+ )
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer row.Close()
+
+ if row.Next() {
+ var column api.Column
+ defaultStr := sql.NullString{}
+ if err := row.Scan(
+ &column.ID,
+ &column.CreatorId,
+ &column.CreatedTs,
+ &column.UpdaterId,
+ &column.UpdatedTs,
+ &column.DatabaseId,
+ &column.TableId,
+ &column.SyncStatus,
+ &column.LastSuccessfulSyncTs,
+ &column.Name,
+ &column.Position,
+ &defaultStr,
+ &column.Nullable,
+ &column.Type,
+ &column.CharacterSet,
+ &column.Collation,
+ &column.Comment,
+ ); err != nil {
+ return nil, FormatError(err)
+ }
+
+ if defaultStr.Valid {
+ column.Default = &defaultStr.String
+ }
+
+ return &column, nil
+ }
+
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("column ID not found: %d", patch.ID)}
+}
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index 8fb2cb983b..f3152fc71f 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -299,11 +299,11 @@ CREATE TABLE db (
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
instance_id INTEGER NOT NULL REFERENCES instance (id),
project_id INTEGER NOT NULL REFERENCES project (id),
+ sync_status TEXT NOT NULL CHECK (sync_status IN ('OK', 'NOT_FOUND')),
+ last_successful_sync_ts BIGINT NOT NULL,
name TEXT NOT NULL,
character_set TEXT NOT NULL,
`collation` TEXT NOT NULL,
- sync_status TEXT NOT NULL CHECK (sync_status IN ('OK', 'NOT_FOUND')),
- last_successful_sync_ts BIGINT NOT NULL,
UNIQUE(instance_id, name)
);
@@ -337,12 +337,12 @@ CREATE TABLE tbl (
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,
name TEXT NOT NULL,
`type` TEXT NOT NULL,
`engine` TEXT NOT NULL,
`collation` TEXT NOT NULL,
- sync_status TEXT NOT NULL CHECK (sync_status IN ('OK', 'NOT_FOUND')),
- last_successful_sync_ts BIGINT NOT NULL,
row_count BIGINT NOT NULL,
data_size BIGINT NOT NULL,
index_size BIGINT NOT NULL,
@@ -372,6 +372,52 @@ WHERE
END;
+-- col stores the column for a particular table from a particular database
+-- data is synced periodically from the instance
+CREATE TABLE col (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ row_status TEXT NOT NULL CHECK (
+ row_status IN ('NORMAL', 'ARCHIVED', 'PENDING_DELETE')
+ ) DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ 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),
+ 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,
+ name TEXT NOT NULL,
+ position INTEGER NOT NULL,
+ `default` TEXT,
+ `nullable` INTEGER NOT NULL,
+ `type` TEXT NOT NULL,
+ character_set TEXT NOT NULL,
+ `collation` TEXT NOT NULL,
+ `comment` TEXT NOT NULL,
+ UNIQUE(database_id, table_id, name)
+);
+
+CREATE INDEX idx_col_database_id_table_id ON col(database_id, table_id);
+
+INSERT INTO
+ sqlite_sequence (name, seq)
+VALUES
+ ('col', 100);
+
+CREATE TRIGGER IF NOT EXISTS `trigger_update_col_modification_time`
+AFTER
+UPDATE
+ ON `col` FOR EACH ROW BEGIN
+UPDATE
+ `col`
+SET
+ updated_ts = (strftime('%s', 'now'))
+WHERE
+ rowid = old.rowid;
+
+END;
+
-- data_source table stores the data source for a particular database
CREATE TABLE data_source (
id INTEGER PRIMARY KEY AUTOINCREMENT,
diff --git a/store/seed/test/10000__reset.sql b/store/seed/test/10000__reset.sql
index 6316f9f38f..a8075daac6 100644
--- a/store/seed/test/10000__reset.sql
+++ b/store/seed/test/10000__reset.sql
@@ -32,6 +32,9 @@ DELETE FROM
DELETE FROM
data_source;
+DELETE FROM
+ col;
+
DELETE FROM
tbl;
diff --git a/store/seed/test/10071__tbl.sql b/store/seed/test/10071__tbl.sql
index 2b8fa0c32d..3f160d8484 100644
--- a/store/seed/test/10071__tbl.sql
+++ b/store/seed/test/10071__tbl.sql
@@ -1,6 +1,7 @@
-- Table for database 7002 testdb_dev
INSERT INTO
tbl (
+ id,
creator_id,
updater_id,
database_id,
@@ -19,6 +20,7 @@ INSERT INTO
)
VALUES
(
+ 7101,
101,
101,
7002,
diff --git a/store/seed/test/10072__col.sql b/store/seed/test/10072__col.sql
new file mode 100644
index 0000000000..1df179564c
--- /dev/null
+++ b/store/seed/test/10072__col.sql
@@ -0,0 +1,1909 @@
+-- Column for database 7002 testdb_dev, table 7101 tbl1
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 7201,
+ 101,
+ 101,
+ 7002,
+ 7101,
+ 'OK',
+ 1625075289,
+ 'col1',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ 'I am a comment'
+ );
+
+-- Column for database 7006 testdb_integration, table 7102 tbl1
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7006,
+ 7102,
+ 'OK',
+ 1625075289,
+ 'col1',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ 'I am a comment'
+ );
+
+-- Column for database 7010 testdb_staging, table 7103 tbl1
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7010,
+ 7103,
+ 'OK',
+ 1625075289,
+ 'col1',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ 'I am a comment'
+ );
+
+-- Column for database 7014 testdb_prod, table 7104 tbl1
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7014,
+ 7104,
+ 'OK',
+ 1625075289,
+ 'col1',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ 'I am a comment'
+ );
+
+-- Column for database 7003 shop, table 7105 product
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7003,
+ 7105,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7003,
+ 7105,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7003,
+ 7105,
+ 'OK',
+ 1625075289,
+ 'description',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7007 shop, table 7106 product
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7007,
+ 7106,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7007,
+ 7106,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7007,
+ 7106,
+ 'OK',
+ 1625075289,
+ 'description',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7004 blog, table 7107 user
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7107,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7107,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7107,
+ 'OK',
+ 1625075289,
+ 'email',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7004 blog, table 7108 post
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7108,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7108,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7108,
+ 'OK',
+ 1625075289,
+ 'content',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7108,
+ 'OK',
+ 1625075289,
+ 'author_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7004 blog, table 7109 comment
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7109,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7109,
+ 'OK',
+ 1625075289,
+ 'content',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7109,
+ 'OK',
+ 1625075289,
+ 'post_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7004,
+ 7109,
+ 'OK',
+ 1625075289,
+ 'author_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7110 user
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7110,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7110,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7110,
+ 'OK',
+ 1625075289,
+ 'email',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7111 post
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7111,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7111,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7111,
+ 'OK',
+ 1625075289,
+ 'content',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7111,
+ 'OK',
+ 1625075289,
+ 'author_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7112 comment
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7112,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7112,
+ 'OK',
+ 1625075289,
+ 'content',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7112,
+ 'OK',
+ 1625075289,
+ 'post_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7008,
+ 7112,
+ 'OK',
+ 1625075289,
+ 'author_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7012 blog, table 7113 user
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7113,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7113,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7113,
+ 'OK',
+ 1625075289,
+ 'email',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7114 post
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7114,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7114,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7114,
+ 'OK',
+ 1625075289,
+ 'content',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7114,
+ 'OK',
+ 1625075289,
+ 'author_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7115 comment
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7115,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7115,
+ 'OK',
+ 1625075289,
+ 'content',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7115,
+ 'OK',
+ 1625075289,
+ 'post_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7012,
+ 7115,
+ 'OK',
+ 1625075289,
+ 'author_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7016 blog, table 7116 user
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7116,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7116,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7116,
+ 'OK',
+ 1625075289,
+ 'email',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7117 post
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7117,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7117,
+ 'OK',
+ 1625075289,
+ 'name',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7117,
+ 'OK',
+ 1625075289,
+ 'content',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7117,
+ 'OK',
+ 1625075289,
+ 'author_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7016 blog, table 7118 comment
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7118,
+ 'OK',
+ 1625075289,
+ 'id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7118,
+ 'OK',
+ 1625075289,
+ 'content',
+ 1,
+ NULL,
+ 0,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7118,
+ 'OK',
+ 1625075289,
+ 'post_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ sync_status,
+ last_successful_sync_ts,
+ name,
+ position,
+ `default`,
+ `nullable`,
+ `type`,
+ character_set,
+ `collation`,
+ `comment`
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 7016,
+ 7118,
+ 'OK',
+ 1625075289,
+ 'author_id',
+ 1,
+ NULL,
+ 0,
+ 'int',
+ '',
+ '',
+ ''
+ );
\ No newline at end of file