Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/dtables/tests_table.go (Go)

Code before:
)

var _ sql.Table = (*TestsTable)(nil)
var _ sql.UpdatableTable = (*TestsTable)(nil)
var _ sql.DeletableTable = (*TestsTable)(nil)
var _ sql.InsertableTable = (*TestsTable)(nil)
var _ sql.ReplaceableTable = (*TestsTable)(nil)
var _ sql.IndexAddressableTable = (*TestsTable)(nil)

// TestsTable is the system table that stores test definitions.
type TestsTable struct {
	backingTable VersionableTable
}

func (tt *TestsTable) Name() string {
	return doltdb.TestsTableName
}

func (tt *TestsTable) String() string {
	return doltdb.TestsTableName
}

func doltTestsSchema() sql.Schema {
	return []*sql.Column{
		{Name: "test_group", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: true},
		{Name: "test_name", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: true},
		{Name: "test_query", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "assertion_type", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "assertion_comparator", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "assertion_value", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
	}
}

// GetDoltTestsSchema returns the schema of the dolt_tests system table. This is used
// by Doltgres to update the dolt_tests schema using Doltgres types.
var GetDoltTestsSchema = doltTestsSchema

// Schema is a sql.Table interface function that gets the sql.Schema of the dolt_tests system table.
func (tt *TestsTable) Schema() sql.Schema {
	return GetDoltTestsSchema()
}

func (tt *TestsTable) Collation() sql.CollationID {
	return sql.Collation_Default
}

// Partitions is a sql.Table interface function that returns a partition of the data.
func (tt *TestsTable) Partitions(context *sql.Context) (sql.PartitionIter, error) {
	if tt.backingTable == nil {
		// no backing table; return an empty iter.
		return index.SinglePartitionIterFromNomsMap(nil), nil

Review comment (suggestion):
I thought we decided to use the name as the PK, and the group would be nullable? Maybe I'm not remembering that right, but seems like a more straight forward approach

Code after:
)

var _ sql.Table = (*TestsTable)(nil)
var _ sql.UpdatableTable = (*TestsTable)(nil)
var _ sql.DeletableTable = (*TestsTable)(nil)
var _ sql.InsertableTable = (*TestsTable)(nil)
var _ sql.ReplaceableTable = (*TestsTable)(nil)
var _ sql.IndexAddressableTable = (*TestsTable)(nil)

// TestsTable is the system table that stores test definitions.
type TestsTable struct {
	backingTable VersionableTable
}

func (tt *TestsTable) Name() string {
	return doltdb.TestsTableName
}

func (tt *TestsTable) String() string {
	return doltdb.TestsTableName
}

func doltTestsSchema() sql.Schema {
	return []*sql.Column{
		{Name: "test_name", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: true},
		{Name: "test_group", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: true},
		{Name: "test_query", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "assertion_type", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "assertion_comparator", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "assertion_value", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
	}
}

// GetDoltTestsSchema returns the schema of the dolt_tests system table. This is used
// by Doltgres to update the dolt_tests schema using Doltgres types.
var GetDoltTestsSchema = doltTestsSchema

// Schema is a sql.Table interface function that gets the sql.Schema of the dolt_tests system table.
func (tt *TestsTable) Schema() sql.Schema {
	return GetDoltTestsSchema()
}

func (tt *TestsTable) Collation() sql.CollationID {
	return sql.Collation_Default
}

// Partitions is a sql.Table interface function that returns a partition of the data.
func (tt *TestsTable) Partitions(context *sql.Context) (sql.PartitionIter, error) {
	if tt.backingTable == nil {
		// no backing table; return an empty iter.
		return index.SinglePartitionIterFromNomsMap(nil), nil