mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-15 11:20:37 -05:00
Merge pull request #4768 from dolthub/james/dolt-docs
change dolt docs `doc_text` column to `longtext`
This commit is contained in:
@@ -20,6 +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/utils/funcitr"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/set"
|
||||
@@ -33,6 +35,25 @@ 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() {
|
||||
docTextCol, err := schema.NewColumnWithTypeInfo(DocTextColumnName, schema.DocTextTag, typeinfo.LongTextType, false, "", false, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
doltDocsColumns := schema.NewColCollection(
|
||||
schema.NewColumn(DocPkColumnName, schema.DocNameTag, types.StringKind, true, schema.NotNullConstraint{}),
|
||||
docTextCol,
|
||||
)
|
||||
DocsSchema = schema.MustSchemaFromCols(doltDocsColumns)
|
||||
}
|
||||
|
||||
// HasDoltPrefix returns a boolean whether or not the provided string is prefixed with the DoltNamespace. Users should
|
||||
// not be able to create tables in this reserved namespace.
|
||||
func HasDoltPrefix(s string) bool {
|
||||
@@ -162,16 +183,10 @@ const (
|
||||
ReadmeDoc = "README.md"
|
||||
)
|
||||
|
||||
var doltDocsColumns = schema.NewColCollection(
|
||||
schema.NewColumn(DocPkColumnName, schema.DocNameTag, types.StringKind, true, schema.NotNullConstraint{}),
|
||||
schema.NewColumn(DocTextColumnName, schema.DocTextTag, types.StringKind, false),
|
||||
)
|
||||
var DocsSchema = schema.MustSchemaFromCols(doltDocsColumns)
|
||||
|
||||
var DocsMaybeCreateTableStmt = `
|
||||
CREATE TABLE IF NOT EXISTS dolt_docs (
|
||||
doc_name varchar(16383) NOT NULL,
|
||||
doc_text varchar(16383),
|
||||
doc_text longtext,
|
||||
PRIMARY KEY (doc_name)
|
||||
);`
|
||||
|
||||
|
||||
@@ -851,7 +851,7 @@ func (db Database) CreateTable(ctx *sql.Context, tableName string, sch sql.Prima
|
||||
}
|
||||
if strings.ToLower(tableName) == doltdb.DocTableName {
|
||||
// validate correct schema
|
||||
if !dtables.DoltDocsSqlSchema.Equals(sch.Schema) {
|
||||
if !dtables.DoltDocsSqlSchema.Equals(sch.Schema) && !dtables.OldDoltDocsSqlSchema.Equals(sch.Schema) {
|
||||
return fmt.Errorf("incorrect schema for dolt_docs table")
|
||||
}
|
||||
} else if doltdb.HasDoltPrefix(tableName) {
|
||||
@@ -872,7 +872,7 @@ func (db Database) CreateIndexedTable(ctx *sql.Context, tableName string, sch sq
|
||||
}
|
||||
if strings.ToLower(tableName) == doltdb.DocTableName {
|
||||
// validate correct schema
|
||||
if !dtables.DoltDocsSqlSchema.Equals(sch.Schema) {
|
||||
if !dtables.DoltDocsSqlSchema.Equals(sch.Schema) && !dtables.OldDoltDocsSqlSchema.Equals(sch.Schema) {
|
||||
return fmt.Errorf("incorrect schema for dolt_docs table")
|
||||
}
|
||||
} else if doltdb.HasDoltPrefix(tableName) {
|
||||
|
||||
@@ -22,7 +22,9 @@ import (
|
||||
)
|
||||
|
||||
var DoltDocsSqlSchema sql.PrimaryKeySchema
|
||||
var OldDoltDocsSqlSchema sql.PrimaryKeySchema
|
||||
|
||||
func init() {
|
||||
DoltDocsSqlSchema, _ = sqlutil.FromDoltSchema(doltdb.DocTableName, doltdb.DocsSchema)
|
||||
OldDoltDocsSqlSchema, _ = sqlutil.FromDoltSchema(doltdb.DocTableName, doltdb.OldDocsSchema)
|
||||
}
|
||||
|
||||
@@ -1292,9 +1292,8 @@ var systemTableSelectTests = []SelectTest{
|
||||
Name: "select from dolt_docs",
|
||||
AdditionalSetup: CreateTableFn("dolt_docs", doltdb.DocsSchema,
|
||||
"INSERT INTO dolt_docs VALUES ('LICENSE.md','A license')"),
|
||||
Query: "select * from dolt_docs",
|
||||
ExpectedRows: ToSqlRows(CompressSchema(doltdb.DocsSchema),
|
||||
NewRow(types.String("LICENSE.md"), types.String("A license"))),
|
||||
Query: "select * from dolt_docs",
|
||||
ExpectedRows: []sql.Row{{"LICENSE.md", "A license"}},
|
||||
ExpectedSchema: CompressSchema(doltdb.DocsSchema),
|
||||
},
|
||||
{
|
||||
|
||||
@@ -111,7 +111,7 @@ teardown() {
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE dolt_docs (
|
||||
doc_name varchar(16383) NOT NULL,
|
||||
doc_text varchar(16383),
|
||||
doc_text longtext,
|
||||
PRIMARY KEY (doc_name)
|
||||
);
|
||||
SQL
|
||||
|
||||
Reference in New Issue
Block a user