Skip to content

Instantly share code, notes, and snippets.

@robstradling
Created November 12, 2024 14:58
Show Gist options
  • Save robstradling/a6857bc6a0cfc0c828c98e4d62c6aa5b to your computer and use it in GitHub Desktop.
Save robstradling/a6857bc6a0cfc0c828c98e4d62c6aa5b to your computer and use it in GitHub Desktop.
Duplicate MySQL IssuanceChainStorage implementation, then search'n'replace a bunch of stuff
#!/bin/bash
git checkout -b duplicate_mysql_to_postgresql
# Duplicate the MySQL "Extra Data Issuance Chain Deduplication" storage layer files into new PostgreSQL directories, preserving git line history.
# (h/t https://devblogs.microsoft.com/oldnewthing/20190919-00/?p=102904)
mkdir trillian/ctfe/storage/postgresql
git mv trillian/ctfe/storage/mysql/mysql.go trillian/ctfe/storage/postgresql/postgresql.go
git mv trillian/ctfe/storage/mysql/mysql_test.go trillian/ctfe/storage/postgresql/postgresql_test.go
git mv trillian/ctfe/storage/mysql/schema.sql trillian/ctfe/storage/postgresql/schema.sql
git commit -m "Duplicate MySQL files to new PostgreSQL directories, preserving git line history"
git checkout HEAD~ trillian/ctfe/storage/mysql
git commit -m "Restore MySQL files"
git checkout -
git checkout -b postgresql_storage_saving
git merge --no-ff --no-edit duplicate_mysql_to_postgresql
git branch -D duplicate_mysql_to_postgresql
# Replace "MySQL" references with "PostgreSQL", preserving case of each reference.
find trillian/ctfe/storage/postgresql -iname "*.go" -exec sed -i "s/mysql/postgresql/g" '{}' ';'
find trillian/ctfe/storage/postgresql -iname "*.go" -exec sed -i "s/MySQL/PostgreSQL/g" '{}' ';'
sed -i "s/MySQL/PostgreSQL/g" trillian/ctfe/storage/postgresql/schema.sql
git commit -a -m "Replace 'MySQL' references with 'PostgreSQL', preserving case of each reference"
# Update imports.
echo "Using gopls to update imports. Please wait..."
find trillian/ctfe/storage/postgresql -iname "*.go" -exec sed -i "s/go-sql-driver\/postgresql/jackc\/pgx\/v5\/stdlib/g" '{}' ';'
find trillian/ctfe/storage/postgresql -iname "*.go" -exec gopls imports -w '{}' ';'
sed -i "s/import (/import (\n\t_ \"github.com\/jackc\/pgx\/v5\/stdlib\"/g" trillian/ctfe/storage/postgresql/postgresql.go
go mod tidy
find trillian/ctfe/storage/postgresql -iname "*.go" -exec gopls imports -w '{}' ';'
git commit -a -m "Update imports"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment