From 4e504a5b3a11b23c7005d06f0b60f1c7f08516b5 Mon Sep 17 00:00:00 2001 From: Taylor Bantle Date: Thu, 26 Sep 2024 14:03:10 -0700 Subject: [PATCH] Add pointer for dolt_docs schema so it can be replaced by doltgres --- go/libraries/doltcore/doltdb/system_table.go | 8 +--- .../doltcore/sqle/dtables/docs_table.go | 41 +++++++++---------- .../node/workbenchTests/docs.js | 2 +- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/go/libraries/doltcore/doltdb/system_table.go b/go/libraries/doltcore/doltdb/system_table.go index 7d3198f981..bb05208b13 100644 --- a/go/libraries/doltcore/doltdb/system_table.go +++ b/go/libraries/doltcore/doltdb/system_table.go @@ -20,9 +20,8 @@ import ( "sort" "strings" - "github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo" - "github.com/dolthub/dolt/go/libraries/doltcore/schema" + "github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo" "github.com/dolthub/dolt/go/libraries/utils/funcitr" "github.com/dolthub/dolt/go/libraries/utils/set" "github.com/dolthub/dolt/go/store/types" @@ -35,11 +34,6 @@ const ( var ErrSystemTableCannotBeModified = errors.New("system tables cannot be dropped or altered") -var OldDocsSchema = schema.MustSchemaFromCols(schema.NewColCollection( - schema.NewColumn(DocPkColumnName, schema.DocNameTag, types.StringKind, true, schema.NotNullConstraint{}), - schema.NewColumn(DocTextColumnName, schema.DocTextTag, types.StringKind, false), -)) - var DocsSchema schema.Schema func init() { diff --git a/go/libraries/doltcore/sqle/dtables/docs_table.go b/go/libraries/doltcore/sqle/dtables/docs_table.go index d13c5d6876..e8d02df6c5 100644 --- a/go/libraries/doltcore/sqle/dtables/docs_table.go +++ b/go/libraries/doltcore/sqle/dtables/docs_table.go @@ -24,18 +24,9 @@ import ( "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/index" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil" "github.com/dolthub/dolt/go/store/hash" ) -var DoltDocsSqlSchema sql.PrimaryKeySchema -var OldDoltDocsSqlSchema sql.PrimaryKeySchema - -func init() { - DoltDocsSqlSchema, _ = sqlutil.FromDoltSchema("", doltdb.DocTableName, doltdb.DocsSchema) - OldDoltDocsSqlSchema, _ = sqlutil.FromDoltSchema("", doltdb.DocTableName, doltdb.OldDocsSchema) -} - var _ sql.Table = (*DocsTable)(nil) var _ sql.UpdatableTable = (*DocsTable)(nil) var _ sql.DeletableTable = (*DocsTable)(nil) @@ -48,6 +39,16 @@ type DocsTable struct { backingTable VersionableTable } +// NewDocsTable creates a DocsTable +func NewDocsTable(_ *sql.Context, backingTable VersionableTable) sql.Table { + return &DocsTable{backingTable: backingTable} +} + +// NewEmptyDocsTable creates a DocsTable +func NewEmptyDocsTable(_ *sql.Context) sql.Table { + return &DocsTable{} +} + func (dt *DocsTable) Name() string { return doltdb.DocTableName } @@ -58,14 +59,22 @@ func (dt *DocsTable) String() string { const defaultStringsLen = 16383 / 16 -// Schema is a sql.Table interface function that gets the sql.Schema of the dolt_docs system table. -func (dt *DocsTable) Schema() sql.Schema { +// GetDocsSchema returns the schema of the dolt_docs system table. This is used +// by Doltgres to update the dolt_docs schema using Doltgres types. +var GetDocsSchema = getDoltDocsSchema + +func getDoltDocsSchema() sql.Schema { return []*sql.Column{ {Name: doltdb.DocPkColumnName, Type: sqlTypes.MustCreateString(sqltypes.VarChar, defaultStringsLen, sql.Collation_Default), Source: doltdb.DocTableName, PrimaryKey: true, Nullable: false}, {Name: doltdb.DocTextColumnName, Type: sqlTypes.LongText, Source: doltdb.DocTableName, PrimaryKey: false}, } } +// Schema is a sql.Table interface function that gets the sql.Schema of the dolt_docs system table. +func (dt *DocsTable) Schema() sql.Schema { + return GetDocsSchema() +} + func (dt *DocsTable) Collation() sql.CollationID { return sql.Collation_Default } @@ -88,16 +97,6 @@ func (dt *DocsTable) PartitionRows(context *sql.Context, partition sql.Partition return dt.backingTable.PartitionRows(context, partition) } -// NewDocsTable creates a DocsTable -func NewDocsTable(_ *sql.Context, backingTable VersionableTable) sql.Table { - return &DocsTable{backingTable: backingTable} -} - -// NewEmptyDocsTable creates a DocsTable -func NewEmptyDocsTable(_ *sql.Context) sql.Table { - return &DocsTable{} -} - // Replacer returns a RowReplacer for this table. The RowReplacer will have Insert and optionally Delete called once // for each row, followed by a call to Close() when all rows have been processed. func (dt *DocsTable) Replacer(ctx *sql.Context) sql.RowReplacer { diff --git a/integration-tests/mysql-client-tests/node/workbenchTests/docs.js b/integration-tests/mysql-client-tests/node/workbenchTests/docs.js index 34e4ef82a2..c0ed5f6c62 100644 --- a/integration-tests/mysql-client-tests/node/workbenchTests/docs.js +++ b/integration-tests/mysql-client-tests/node/workbenchTests/docs.js @@ -11,7 +11,7 @@ export const docsTests = [ res: [], }, { - q: "INSERT INTO dolt_docs VALUES (:docName, :docText) ON DUPLICATE KEY UPDATE doc_text=:docText", + q: "REPLACE INTO dolt_docs VALUES (:docName, :docText);", p: { docName: "README.md", docText: readmeText,