Skip to content

Commit

Permalink
Begin positioning EAV for non complete-insert mysqldump
Browse files Browse the repository at this point in the history
  • Loading branch information
mpchadwick committed Nov 1, 2020
1 parent 747cf0d commit ce344c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/eav.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ func NewEav(c *Config) *Eav {
func (eav Eav) ProcessLine(s string) {
// TODO: DRY up duplicated code from LineProcessor.ProcessLine
i := strings.Index(s, "INSERT")
if i != 0 {
if i == 0 {
eav.processInsert(s)
return
}
}

func (eav Eav) processInsert (s string) {
stmt, _ := sqlparser.Parse(s)
switch stmt := stmt.(type) {
case *sqlparser.Insert:
Expand Down
12 changes: 12 additions & 0 deletions src/eav_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ import (
func TestEavProcessLine(t *testing.T) {
config, _ := NewConfig("magento2")
eav := NewEav(config)
eav.ProcessLine("CREATE TABLE `eav_entity_type` (")
eav.ProcessLine(" `entity_type_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Type ID',")
eav.ProcessLine(" `entity_type_code` varchar(50) NOT NULL COMMENT 'Entity Type Code'")
eav.ProcessLine(") ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COMMENT='Eav Entity Type';")
eav.ProcessLine("/*!40101 SET character_set_client = @saved_cs_client */;")
eav.ProcessLine("INSERT INTO `eav_entity_type` (`entity_type_id`, `entity_type_code`) VALUES (1, 'customer');")

eav.ProcessLine("CREATE TABLE `eav_attribute` (")
eav.ProcessLine(" `attribute_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Attribute ID',")
eav.ProcessLine(" `entity_type_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type ID',")
eav.ProcessLine(" `attribute_code` varchar(255) NOT NULL COMMENT 'Attribute Code'")
eav.ProcessLine(") ENGINE=InnoDB AUTO_INCREMENT=180 DEFAULT CHARSET=utf8 COMMENT='Eav Attribute';")
eav.ProcessLine("/*!40101 SET character_set_client = @saved_cs_client */;")
eav.ProcessLine("INSERT INTO `eav_attribute` (`attribute_id`, `entity_type_id`, `attribute_code`) VALUES (1, 1, 'firstname');")
r1 := false
for _, eavConfig := range eav.Config.Eav {
Expand Down

0 comments on commit ce344c6

Please sign in to comment.