Skip to content

Commit 9601142

Browse files
authored
Merge pull request #8398 from dolthub/taylor/docs
Add pointer for dolt_docs schema so it can be replaced by doltgres
2 parents 88f872a + 4e504a5 commit 9601142

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

go/libraries/doltcore/doltdb/system_table.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import (
2020
"sort"
2121
"strings"
2222

23-
"github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo"
24-
2523
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
24+
"github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo"
2625
"github.com/dolthub/dolt/go/libraries/utils/funcitr"
2726
"github.com/dolthub/dolt/go/libraries/utils/set"
2827
"github.com/dolthub/dolt/go/store/types"
@@ -35,11 +34,6 @@ const (
3534

3635
var ErrSystemTableCannotBeModified = errors.New("system tables cannot be dropped or altered")
3736

38-
var OldDocsSchema = schema.MustSchemaFromCols(schema.NewColCollection(
39-
schema.NewColumn(DocPkColumnName, schema.DocNameTag, types.StringKind, true, schema.NotNullConstraint{}),
40-
schema.NewColumn(DocTextColumnName, schema.DocTextTag, types.StringKind, false),
41-
))
42-
4337
var DocsSchema schema.Schema
4438

4539
func init() {

go/libraries/doltcore/sqle/dtables/docs_table.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,9 @@ import (
2424
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
2525
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
2626
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/index"
27-
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil"
2827
"github.com/dolthub/dolt/go/store/hash"
2928
)
3029

31-
var DoltDocsSqlSchema sql.PrimaryKeySchema
32-
var OldDoltDocsSqlSchema sql.PrimaryKeySchema
33-
34-
func init() {
35-
DoltDocsSqlSchema, _ = sqlutil.FromDoltSchema("", doltdb.DocTableName, doltdb.DocsSchema)
36-
OldDoltDocsSqlSchema, _ = sqlutil.FromDoltSchema("", doltdb.DocTableName, doltdb.OldDocsSchema)
37-
}
38-
3930
var _ sql.Table = (*DocsTable)(nil)
4031
var _ sql.UpdatableTable = (*DocsTable)(nil)
4132
var _ sql.DeletableTable = (*DocsTable)(nil)
@@ -48,6 +39,16 @@ type DocsTable struct {
4839
backingTable VersionableTable
4940
}
5041

42+
// NewDocsTable creates a DocsTable
43+
func NewDocsTable(_ *sql.Context, backingTable VersionableTable) sql.Table {
44+
return &DocsTable{backingTable: backingTable}
45+
}
46+
47+
// NewEmptyDocsTable creates a DocsTable
48+
func NewEmptyDocsTable(_ *sql.Context) sql.Table {
49+
return &DocsTable{}
50+
}
51+
5152
func (dt *DocsTable) Name() string {
5253
return doltdb.DocTableName
5354
}
@@ -58,14 +59,22 @@ func (dt *DocsTable) String() string {
5859

5960
const defaultStringsLen = 16383 / 16
6061

61-
// Schema is a sql.Table interface function that gets the sql.Schema of the dolt_docs system table.
62-
func (dt *DocsTable) Schema() sql.Schema {
62+
// GetDocsSchema returns the schema of the dolt_docs system table. This is used
63+
// by Doltgres to update the dolt_docs schema using Doltgres types.
64+
var GetDocsSchema = getDoltDocsSchema
65+
66+
func getDoltDocsSchema() sql.Schema {
6367
return []*sql.Column{
6468
{Name: doltdb.DocPkColumnName, Type: sqlTypes.MustCreateString(sqltypes.VarChar, defaultStringsLen, sql.Collation_Default), Source: doltdb.DocTableName, PrimaryKey: true, Nullable: false},
6569
{Name: doltdb.DocTextColumnName, Type: sqlTypes.LongText, Source: doltdb.DocTableName, PrimaryKey: false},
6670
}
6771
}
6872

73+
// Schema is a sql.Table interface function that gets the sql.Schema of the dolt_docs system table.
74+
func (dt *DocsTable) Schema() sql.Schema {
75+
return GetDocsSchema()
76+
}
77+
6978
func (dt *DocsTable) Collation() sql.CollationID {
7079
return sql.Collation_Default
7180
}
@@ -88,16 +97,6 @@ func (dt *DocsTable) PartitionRows(context *sql.Context, partition sql.Partition
8897
return dt.backingTable.PartitionRows(context, partition)
8998
}
9099

91-
// NewDocsTable creates a DocsTable
92-
func NewDocsTable(_ *sql.Context, backingTable VersionableTable) sql.Table {
93-
return &DocsTable{backingTable: backingTable}
94-
}
95-
96-
// NewEmptyDocsTable creates a DocsTable
97-
func NewEmptyDocsTable(_ *sql.Context) sql.Table {
98-
return &DocsTable{}
99-
}
100-
101100
// Replacer returns a RowReplacer for this table. The RowReplacer will have Insert and optionally Delete called once
102101
// for each row, followed by a call to Close() when all rows have been processed.
103102
func (dt *DocsTable) Replacer(ctx *sql.Context) sql.RowReplacer {

integration-tests/mysql-client-tests/node/workbenchTests/docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const docsTests = [
1111
res: [],
1212
},
1313
{
14-
q: "INSERT INTO dolt_docs VALUES (:docName, :docText) ON DUPLICATE KEY UPDATE doc_text=:docText",
14+
q: "REPLACE INTO dolt_docs VALUES (:docName, :docText);",
1515
p: {
1616
docName: "README.md",
1717
docText: readmeText,

0 commit comments

Comments
 (0)