Add pointer for dolt_docs schema so it can be replaced by doltgres

This commit is contained in:
Taylor Bantle
2024-09-26 14:03:10 -07:00
parent 88f872a6ff
commit 4e504a5b3a
3 changed files with 22 additions and 29 deletions

View File

@@ -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() {

View File

@@ -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 {

View File

@@ -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,