Skip to content

unnecessary enum type generated for actual schema  #2475

Closed

Description

@maksim-ramenskiy

Version

1.19.1

What happened?

The code associated with the enum field is generated even if the table is dropped after define this field.

Relevant log output

type StreamSessionState string

const (
	StreamSessionStateACTIVATING                StreamSessionState = "ACTIVATING"
	StreamSessionStateACTIVE                    StreamSessionState = "ACTIVE"
	StreamSessionStateCONNECTED                 StreamSessionState = "CONNECTED"
	StreamSessionStatePENDINGCLIENTRECONNECTION StreamSessionState = "PENDING_CLIENT_RECONNECTION"
	StreamSessionStateTERMINATED                StreamSessionState = "TERMINATED"
	StreamSessionStateERROR                     StreamSessionState = "ERROR"
)

func (e *StreamSessionState) Scan(src interface{}) error {
	switch s := src.(type) {
	case []byte:
		*e = StreamSessionState(s)
	case string:
		*e = StreamSessionState(s)
	default:
		return fmt.Errorf("unsupported scan type for StreamSessionState: %T", src)
	}
	return nil
}

type NullStreamSessionState struct {
	StreamSessionState StreamSessionState
	Valid                      bool // Valid is true if StreamSessionState is not NULL
}

// Scan implements the Scanner interface.
func (ns *NullStreamSessionState) Scan(value interface{}) error {
	if value == nil {
		ns.StreamSessionState, ns.Valid = "", false
		return nil
	}
	ns.Valid = true
	return ns.StreamSessionState.Scan(value)
}

// Value implements the driver Valuer interface.
func (ns NullStreamSessionState) Value() (driver.Value, error) {
	if !ns.Valid {
		return nil, nil
	}
	return string(ns.StreamSessionState), nil
}

Database schema

CREATE TABLE `stream_session` (
  `id` int NOT NULL AUTO_INCREMENT,
  `external_id` varchar(256) DEFAULT NULL,
  `stream_group_id` int NOT NULL,
  `state` enum('ACTIVATING','ACTIVE','CONNECTED','PENDING_CLIENT_RECONNECTION','TERMINATED','ERROR') NOT NULL,
  PRIMARY KEY (`id`),
  KEY `stream_group_id` (`stream_group_id`),
  CONSTRAINT `stream_session_ibfk_1` FOREIGN KEY (`stream_group_id`) REFERENCES `stream_group` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DROP TABLE stream_session;

SQL queries

No response

Configuration

version: "2"
sql:
- schema: "db/schema/DDL"
  queries: "db/query"
  engine: "mysql"
  gen:
    go:
      package: "db"
      out: "db/sqlc"    
      emit_json_tags: true
      emit_interface: true
      emit_empty_slices: true
      emit_exact_table_names: true

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Jul 18, 2023
  2. changed the title [-]enum type generated for dropped table[/-] [+]unnecessary enum type generated for actual schema [/+] on Jul 19, 2023
  3. andrewmbenton commented on Jul 24, 2023

    @andrewmbenton
    Member

    If you use the config option omit_unused_structs I think sqlc won't generate that enum. But it does seem like this is a bug.

  4. added this to the 1.23.0 milestone on Oct 2, 2023
  5. added a commit that references this issue on Oct 13, 2023
    39576d6
  6. added a commit that references this issue on Oct 13, 2025
    ecfd2dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions