Spanner 数据库 Schema 迁移
perf spanner migrations
在 Performance Dashboard (perf) 中执行数据库 schema 迁移、修改表结构以及重新生成 Spanner schema 文件的操作说明。
- License 许可
- BSD-3-Clause
- 最近更新
- 2026-11-14
- Stars
- ★ 178
- Forks
- 90
01 前言 Front Matter
- name
- perf spanner migrations
- description
- Instructions for performing database schema migrations, modifying tables, and regenerating Spanner schema files in the Performance Dashboard (perf).
02 资源文件 26
- 其他.env.example6.8 KB
- 参考文档plans/251120-2323-google-models-update/phase-01-model-catalog.md5.4 KB
- 参考文档plans/251120-2323-google-models-update/phase-02-environment-config.md6.8 KB
- 参考文档plans/251120-2323-google-models-update/phase-03-image-generation.md9.7 KB
- 参考文档plans/251120-2323-google-models-update/phase-04-video-generation.md15.6 KB
- 参考文档plans/251120-2323-google-models-update/phase-05-script-enhancement.md13.8 KB
- 参考文档plans/251120-2323-google-models-update/phase-06-reference-docs.md8.4 KB
- 参考文档plans/251120-2323-google-models-update/phase-07-testing.md16.3 KB
- 参考文档plans/251120-2323-google-models-update/plan.md2.4 KB
- 参考文档references/audio-processing.md9.5 KB
- 参考文档references/image-generation.md18.1 KB
- 参考文档references/video-analysis.md11.6 KB
- 参考文档references/video-generation.md10.8 KB
- 参考文档references/vision-understanding.md10.8 KB
- 脚本scripts/.coverage52.0 KB
- 脚本scripts/check_setup.py8.5 KB
- 脚本scripts/document_converter.py12.2 KB
- 脚本scripts/gemini_batch_process.py28.2 KB
- 脚本scripts/media_optimizer.py16.1 KB
- 脚本scripts/requirements.txt442 B
- 脚本scripts/tests/.coverage52.0 KB
- 脚本scripts/tests/requirements.txt352 B
- 脚本scripts/tests/test_document_converter.py2.2 KB
- 脚本scripts/tests/test_failures.log17.6 KB
- 脚本scripts/tests/test_gemini_batch_process.py12.4 KB
- 脚本scripts/tests/test_media_optimizer.py11.5 KB
03 SKILL.md 正文
Performance Dashboard (perf) Cloud Spanner Schema Migrations
Use this skill when modifying the database schema, adding new database tables, writing SQL migrations, or regenerating Go/JSON schema target files in perf/go/sql.
Workflow for Schema Changes
When modifying the database schema, follow these sequential steps:
1. Create a New Migration File
Add a new sequence-numbered SQL file inside perf/go/sql/expectedschema/migrations/:
- Format:
000X_description.sql(e.g.,0004_add_metadata_column.sql). - Sequence numbers must be strictly sequential (no gaps or duplicate versions).
- Cloud Spanner has strict schema modification constraints (e.g., you cannot change a column's type to
ARRAYor to incompatible types directly; add a new column instead).
[!IMPORTANT] > Write Idempotent DDL Queries In Spanner, DDL queries are non-transactional. This means DDL statements (like
CREATE TABLEorALTER TABLE) and updating theschema_migrationstracking table are not atomic. If the program crashes or is interrupted after the DDL completes but before the version is recorded, the maintenance runner will try to rerun the DDL on the next execution, resulting in errors (e.g., "Duplicate name in schema").Always write DDL queries in an idempotent way so they are safe to rerun:
-- Example: Create Table CREATE TABLE IF NOT EXISTS dummytable ( id TEXT PRIMARY KEY, dummy_value TEXT ); -- Example: Add Column ALTER TABLE dummytable ADD COLUMN IF NOT EXISTS extra_value TEXT;
2. Update Table Structs
Modify the Go structs representing the table layouts in tables.go to match the new schema layout.
3. Regenerate the Go Schema File
Regenerate schema_spanner.go from the structs:
cd perf/go/sql
go generate
(This executes //perf/go/sql/tosql under the hood to write the target SQL declarations).
4. Regenerate the expected JSON Catalog Description
Regenerate schema_spanner.json:
[!IMPORTANT] Because Bazel runs commands inside sandboxed output directories, passing a relative path to
--outwill write the file into Bazel's output cache instead of your actual workspace. Always use an absolute path (e.g.$(pwd)/...or$(git rev-parse --show-toplevel)/...) for the output file:
cd perf
bazelisk run --config=mayberemote //perf/go/sql/exportschema -- \
--out $(pwd)/go/sql/expectedschema/schema_spanner.json \
--databaseType spanner
5. Verify and Run Unit Tests
To run database tests locally against the emulator:
- Launch a clean Spanner Emulator instance:
make -C perf run-spanner-emulator - Export the connection environment variables:
export PGADAPTER_HOST=localhost:5432 export SPANNER_EMULATOR_HOST=localhost:9010 - Run the SQL package tests:
bazelisk test //perf/go/sql/...
04 同仓库更多 Skills
Pinpoint Web UI 开发规范
pinpoint webui contributor
提供有关如何为 /pinpoint/webui 目录中的 Pinpoint Web UI Angular 项目贡献代码的说明和编码规范。该目录中的任何代码更改都应遵循此技能。
Pinpoint Web UI 开发规范
pinpoint webui contributor
提供有关如何为 /pinpoint/webui 目录中的 Pinpoint Web UI Angular 项目贡献代码的说明和编码规范。该目录中的任何代码更改都应遵循此技能。