Skip to content

v1: use index name for func name - #211

Merged
sinmetal merged 2 commits into
cloudspannerecosystem:masterfrom
sinmetal:v1/use-index-name-for-func-name
Oct 21, 2026
Merged

sinmetal merged 2 commits into
cloudspannerecosystem:masterfrom
sinmetal:v1/use-index-name-for-func-name

Conversation

@sinmetal

Copy link
Copy Markdown
Collaborator

WHAT

I created an option for v1 to generate function names from INDEX names, similar to v2. In v1.
An option --use-index-name-for-func-name-index was also provided to individually specify INDEXes so that it can be enabled for only a subset of them.

WHY

function names are generated by concatenating column names, but this has several issues

Collisions occur when different INDEXes exist on the same column:

Duplicating an INDEX on the same column to avoid hotspots results in function name collisions.

STORING columns are included in the function name:

Adding a STORING column to an existing index changes the function name. Moreover, since STORING columns are not used for filtering, it results in function names like FindByCreateTimeUserID(ctx, db, userID).

Index func names are built by concatenating storing column names and
index column names, so adding a STORING column to an index changes the
func name, even though storing columns are not used as filter conditions.

Add options to build index func names from index names instead, which is
the same naming as yo v2:

- --use-index-name-for-func-name: apply to all indexes
- --use-index-name-for-func-name-index: apply only to the given indexes
  (can be specified multiple times) to migrate index by index.
  An error is returned if the given index is not found.

Also fix the README description of the default naming convention.
- Return an error when generated index func names conflict, which can
  happen when func names built from index names and from index column
  names are mixed.
- Do not treat an index as not found when its table is excluded by
  --ignore-tables or --target-tables. Only indexes that do not exist in
  the schema are reported.
- Compare index names case insensitively, as Spanner identifiers are
  case insensitive.
- Return ErrIndexNotFound from internal and add the flag name in cmd.
- Share the func name prefix logic between the two naming modes.
@sinmetal
sinmetal marked this pull request as ready for review October 20, 2026 10:52
@sinmetal
sinmetal merged commit 69b6bb5 into cloudspannerecosystem:master Oct 21, 2026
11 checks passed
@sinmetal
sinmetal deleted the v1/use-index-name-for-func-name branch October 21, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants