Skip to content

Commit

Permalink
Merge pull request #8398 from dolthub/taylor/docs
Browse files Browse the repository at this point in the history
Add pointer for dolt_docs schema so it can be replaced by doltgres
  • Loading branch information
tbantle22 authored Sep 26, 2024
2 parents 88f872a + 4e504a5 commit 9601142
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
8 changes: 1 addition & 7 deletions go/libraries/doltcore/doltdb/system_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand Down
41 changes: 20 additions & 21 deletions go/libraries/doltcore/sqle/dtables/docs_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9601142

Please sign in to comment.