Skip to content

Commit

Permalink
initial work on key entities
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed Jun 25, 2024
1 parent f64a427 commit f31fb70
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions go/vt/schemadiff/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package schemadiff

import (
"vitess.io/vitess/go/vt/sqlparser"
)

type IndexDefinitionEntity struct {
IndexDefinition *sqlparser.IndexDefinition
Env *Environment
}

func NewIndexDefinitionEntity(env *Environment, i *sqlparser.IndexDefinition) *IndexDefinitionEntity {
return &IndexDefinitionEntity{
IndexDefinition: i,
Env: env,
}
}

func (i *IndexDefinitionEntity) Name() string {
return i.IndexDefinition.Info.Name.String()
}

func (i *IndexDefinitionEntity) NameLowered() string {
return i.IndexDefinition.Info.Name.Lowered()
}

func (i *IndexDefinitionEntity) Clone() *IndexDefinitionEntity {
clone := &IndexDefinitionEntity{
IndexDefinition: sqlparser.Clone(i.IndexDefinition),
Env: i.Env,
}
return clone
}

func (i *IndexDefinitionEntity) Len() int {
return len(i.IndexDefinition.Columns)
}

func (i *IndexDefinitionEntity) IsPrimary() bool {
return i.IndexDefinition.Info.Type == sqlparser.IndexTypePrimary
}

func (i *IndexDefinitionEntity) IsUnique() bool {
return i.IndexDefinition.Info.IsUnique()
}

0 comments on commit f31fb70

Please sign in to comment.