diff --git a/blockchain/common/types.go b/blockchain/common/types.go index 7ae532a..428bd80 100644 --- a/blockchain/common/types.go +++ b/blockchain/common/types.go @@ -51,3 +51,9 @@ type TraceResult struct { GasUsed *big.Int `json:"gasUsed"` Output string `json:"output"` } + +type ProtoTemplateData struct { + GoPackage string + ChainName string + IsL2 bool +} diff --git a/blockchain/handlers.go b/blockchain/handlers.go index 2ec0c33..efad667 100644 --- a/blockchain/handlers.go +++ b/blockchain/handlers.go @@ -5,8 +5,13 @@ import ( "context" "errors" "fmt" + "html/template" + "io/ioutil" "log" "math/big" + "os" + "path/filepath" + "strings" "sync" "time" @@ -83,6 +88,24 @@ func NewClient(chain, url string, timeout int) (BlockchainClient, error) { } } +func CommonClient(url string) (*seer_common.EvmClient, error) { + client, err := seer_common.NewEvmClient(url, 4) + return client, err +} + +type ChainInfo struct { + ChainType string `json:"chainType"` // L1 or L2 + ChainID *big.Int `json:"chainID"` // Chain ID + Block *seer_common.BlockJson `json:"block"` +} + +type BlockchainTemplateData struct { + BlockchainName string + BlockchainNameLower string + ChainDashName string + IsSideChain bool +} + type BlockData struct { BlockNumber uint64 BlockHash string @@ -274,3 +297,258 @@ func FindDeployedBlock(client BlockchainClient, address string) (uint64, error) return left, nil } + +func CollectChainInfo(client seer_common.EvmClient) (*ChainInfo, error) { + ctx := context.Background() + + ctx, cancel := context.WithTimeout(ctx, 10*time.Second) + + defer cancel() + + var chainInfo ChainInfo + + // Get chain id + chainID, err := client.GetChainID(ctx) + + if err != nil { + log.Printf("Failed to get chain id: %v", err) + return nil, err + } + + chainInfo.ChainID = chainID + + // Get latest block number + latestBlockNumber, err := client.GetLatestBlockNumber() + + if err != nil { + log.Printf("Failed to get latest block number: %v", err) + return nil, err + } + + // Get block by number + + ctx, cancel = context.WithTimeout(ctx, 10*time.Second) + + defer cancel() + + block, err := client.GetBlockByNumber(ctx, latestBlockNumber, true) + + if err != nil { + log.Printf("Failed to get block by number: %v", err) + return nil, err + } + + chainInfo.Block = block + + // Initialize a score + l2Score := 0 + + // Method 1: Check for L2-specific fields + + // Check for L2-specific fields + if block.L1BlockNumber != "" { + l2Score++ + } + if block.SendRoot != "" { + l2Score++ + } + + if l2Score >= 1 { + chainInfo.ChainType = "L2" + } else { + chainInfo.ChainType = "L1" + } + + return &chainInfo, nil + +} + +func GenerateProtoFile(chainName string, goPackage string, isL2 bool, outputPath string) error { + tmplData := seer_common.ProtoTemplateData{ + GoPackage: goPackage, + ChainName: chainName, + IsL2: isL2, + } + + // Read the template file + tmplContent, err := ioutil.ReadFile("./blockchain/common/evm_proto_template.proto.tmpl") + if err != nil { + return fmt.Errorf("failed to read template file: %v", err) + } + + // Parse the template + tmpl, err := template.New("proto").Parse(string(tmplContent)) + if err != nil { + return fmt.Errorf("failed to parse template: %v", err) + } + + // Execute the template with data + var output bytes.Buffer + err = tmpl.Execute(&output, tmplData) + if err != nil { + return fmt.Errorf("failed to execute template: %v", err) + } + + // Write the output to the specified path + err = ioutil.WriteFile(outputPath, output.Bytes(), 0644) + if err != nil { + return fmt.Errorf("failed to write proto file: %v", err) + } + + fmt.Printf("Protobuf definitions generated successfully at %s.\n", outputPath) + return nil +} + +func ProtoKeys(msg proto.Message) []string { + m := make([]string, 0) + messageReflect := msg.ProtoReflect() + fields := messageReflect.Descriptor().Fields() + for i := 0; i < fields.Len(); i++ { + fieldDesc := fields.Get(i) + fieldName := string(fieldDesc.Name()) + m = append(m, fieldName) + + } + return m +} + +func GenerateModelsFiles(data BlockchainTemplateData, modelsPath string) error { + + // Define the directory path + //dirPath := filepath.Join(modelsPath, data.BlockchainNameLower) + + // Check if the directory exists + // if _, err := os.Stat(dirPath); os.IsNotExist(err) { + // // Create the directory along with any necessary parents + // if err := os.MkdirAll(dirPath, 0755); err != nil { + // return fmt.Errorf("failed to create directory %s: %v", dirPath, err) + // } + // } + templateIndexFile := fmt.Sprintf("%s/models_indexes.py.tmpl", modelsPath) + templateLabelsFile := fmt.Sprintf("%s/models_labels.py.tmpl", modelsPath) + + // Read the template file + tmplIndexContent, err := ioutil.ReadFile(templateIndexFile) + if err != nil { + return fmt.Errorf("failed to read template file: %v", err) + } + + tmplLabelsContent, err := ioutil.ReadFile(templateLabelsFile) + if err != nil { + return fmt.Errorf("failed to read template file: %v", err) + } + + // Parse the template + tmplIndex, err := template.New("indexes").Parse(string(tmplIndexContent)) + if err != nil { + return fmt.Errorf("failed to parse template: %v", err) + } + + tmplLabels, err := template.New("labels").Parse(string(tmplLabelsContent)) + if err != nil { + return fmt.Errorf("failed to parse template: %v", err) + } + + // Execute the template with data + var outputIndex bytes.Buffer + err = tmplIndex.Execute(&outputIndex, data) + if err != nil { + return fmt.Errorf("failed to execute template: %v", err) + } + + var outputLabels bytes.Buffer + err = tmplLabels.Execute(&outputLabels, data) + if err != nil { + return fmt.Errorf("failed to execute template: %v", err) + } + + outputPath := fmt.Sprintf("%s/models_indexes/%s_indexes.py", modelsPath, data.BlockchainNameLower) + + // Write the output to the specified path + err = ioutil.WriteFile(outputPath, outputIndex.Bytes(), 0644) + if err != nil { + return fmt.Errorf("failed to write models file: %v", err) + } + + outputPath = fmt.Sprintf("%s/models/%s_labels.py", modelsPath, data.BlockchainNameLower) + err = ioutil.WriteFile(outputPath, outputLabels.Bytes(), 0644) + if err != nil { + return fmt.Errorf("failed to write models file: %v", err) + } + + fmt.Printf("Models generated successfully at %s.\n", outputPath) + return nil +} + +func GenerateDeploy(chain BlockchainTemplateData, deployPath string) error { + funcMap := template.FuncMap{ + "replaceUnderscoreWithDash": func(s string) string { + return strings.ReplaceAll(s, "_", "-") + }, + "replaceUnderscoreWithSpace": func(s string) string { + return strings.ReplaceAll(s, "_", " ") + }, + } + + templateDir := "deploy/templates" + + // Read all entries in the template directory + entries, err := os.ReadDir(templateDir) + if err != nil { + return err + } + + for _, entry := range entries { + if entry.IsDir() { + continue // Skip directories + } + + templateFileName := entry.Name() + // Only process files with .tmpl extension + if !strings.HasSuffix(templateFileName, ".tmpl") { + continue + } + + templateFilePath := filepath.Join(templateDir, templateFileName) + + // Parse the template file + tmpl, parseErr := template.New(templateFileName).Funcs(funcMap).ParseFiles(templateFilePath) + if parseErr != nil { + return parseErr + } + + // Generate the output file name + outputFileName := generateOutputFileName(templateFileName, chain.ChainDashName) + outputFilePath := filepath.Join(deployPath, outputFileName) + + // Create the output file + outputFile, createErr := os.Create(outputFilePath) + if createErr != nil { + return createErr + } + defer outputFile.Close() + + // Execute the template and write to the output file + if err := tmpl.Execute(outputFile, chain); err != nil { + return err + } + + log.Printf("File generated successfully: %s", outputFilePath) + } + + return nil +} + +// Helper function to generate output file names dynamically +func generateOutputFileName(templateFileName, chainName string) string { + // Remove the .tmpl extension + baseFileName := strings.TrimSuffix(templateFileName, ".tmpl") + + // Split the file name into name and extension + ext := filepath.Ext(baseFileName) + name := strings.TrimSuffix(baseFileName, ext) + + // Insert the chain name before the extension + outputFileName := fmt.Sprintf("%s-%s%s", name, chainName, ext) + return outputFileName +} diff --git a/cmd.go b/cmd.go index badd1e5..3294aac 100644 --- a/cmd.go +++ b/cmd.go @@ -10,6 +10,7 @@ import ( "io" "log" "os" + "os/exec" "path/filepath" "strconv" "strings" @@ -17,6 +18,7 @@ import ( "github.com/spf13/cobra" + "github.com/G7DAO/seer/blockchain" seer_blockchain "github.com/G7DAO/seer/blockchain" "github.com/G7DAO/seer/crawler" "github.com/G7DAO/seer/evm" @@ -48,7 +50,8 @@ func CreateRootCommand() *cobra.Command { abiCmd := CreateAbiCommand() dbCmd := CreateDatabaseOperationCommand() historicalSyncCmd := CreateHistoricalSyncCommand() - rootCmd.AddCommand(completionCmd, versionCmd, blockchainCmd, starknetCmd, evmCmd, crawlerCmd, inspectorCmd, synchronizerCmd, abiCmd, dbCmd, historicalSyncCmd) + genereateGenerateCmd := CreateGenerateCommand() + rootCmd.AddCommand(completionCmd, versionCmd, blockchainCmd, starknetCmd, evmCmd, crawlerCmd, inspectorCmd, synchronizerCmd, abiCmd, dbCmd, historicalSyncCmd, genereateGenerateCmd) // By default, cobra Command objects write to stderr. We have to forcibly set them to output to // stdout. @@ -138,12 +141,6 @@ func CreateBlockchainCommand() *cobra.Command { return blockchainCmd } -type BlockchainTemplateData struct { - BlockchainName string - BlockchainNameLower string - IsSideChain bool -} - func CreateBlockchainGenerateCommand() *cobra.Command { var blockchainNameLower string var sideChain bool @@ -182,7 +179,7 @@ func CreateBlockchainGenerateCommand() *cobra.Command { defer outputFile.Close() // Execute template and write to output file - data := BlockchainTemplateData{ + data := blockchain.BlockchainTemplateData{ BlockchainName: blockchainName, BlockchainNameLower: blockchainNameLower, IsSideChain: sideChain, @@ -1296,6 +1293,284 @@ func CreateEVMGenerateCommand() *cobra.Command { return evmGenerateCmd } +func CreateGenerateCommand() *cobra.Command { + rootCmd := &cobra.Command{ + Use: "generates", + Short: "A tool for generating Go bindings, crawlers, and other code", + Run: func(cmd *cobra.Command, args []string) { + cmd.Help() + }, + } + + evmCmd := CreateEVMCommand() + starknetCmd := CreateStarknetCommand() + + rootCmd.AddCommand(evmCmd, starknetCmd) + rootCmd.AddCommand(CreateGenerateBlockchainCmd()) + + return rootCmd +} + +func CreateGenerateBlockchainCmd() *cobra.Command { + rootCmd := &cobra.Command{ + Use: "blockchain", + Short: "Generate blockchain definitions and scripts", + Run: func(cmd *cobra.Command, args []string) { + cmd.Help() + }, + } + + definitionsCmd := CreateDefinitionsCommand() + + rootCmd.AddCommand(definitionsCmd) + + return rootCmd +} + +func CreateDefinitionsCommand() *cobra.Command { + + var rpc, chainName, outputPath string + var defenitions, models, clientInteraface, migrations, full, createSubscriptionType, deployScripts, L2Flag bool + var alembicLabelsConfig, alembicIndexesConfig string + + definitionsCmd := &cobra.Command{ + Use: "chain", + Short: "Generate definitions for various blockchains", + RunE: func(cmd *cobra.Command, args []string) error { + client, err := blockchain.CommonClient(rpc) + if err != nil { + log.Printf("Failed to create client: %s", err) + return err + } + + chainInfo, err := blockchain.CollectChainInfo(*client) + if err != nil { + log.Printf("Failed to collect chain info: %s", err) + return err + } + + // dump chain info as json formated to the output file + if outputPath != "" { + file, err := os.Create(outputPath) + if err != nil { + log.Printf("Failed to create output file: %s", err) + return err + } + // dump chain info as json formated to the output file + jsonChainInfo, err := json.MarshalIndent(chainInfo, "", " ") + if err != nil { + log.Printf("Failed to marshal chain info: %s", err) + return err + } + _, err = file.Write(jsonChainInfo) + if err != nil { + log.Printf("Failed to write chain info to the output file: %s", err) + return err + } + log.Printf("Chain info written to %s", outputPath) + } + + var sideChain bool + + if chainInfo.ChainType == "L2" || L2Flag { + sideChain = true + } + + var blockchainName string + blockchainNameList := strings.Split(chainName, "_") + for _, w := range blockchainNameList { + blockchainName += strings.Title(w) + } + + // Execute template and write to output file + data := blockchain.BlockchainTemplateData{ + BlockchainName: blockchainName, + BlockchainNameLower: chainName, + IsSideChain: sideChain, + ChainDashName: strings.ReplaceAll(chainName, "_", "-"), + } + + goPackage := fmt.Sprintf("github.com/moonstream-to/seer/blockchain/%s", strings.ToLower(data.BlockchainNameLower)) + + // check if the chain folder exists + if _, err := os.Stat(fmt.Sprintf("./blockchain/%s", data.BlockchainNameLower)); os.IsNotExist(err) { + err := os.Mkdir(fmt.Sprintf("./blockchain/%s", data.BlockchainNameLower), 0755) + if err != nil { + return err + } + } + + // Generate Proto file + + if defenitions || full { + // chain folder + chainFolder := fmt.Sprintf("./blockchain/%s", data.BlockchainNameLower) + // check if the chain folder exists + if _, err := os.Stat(chainFolder); os.IsNotExist(err) { + err := os.Mkdir(chainFolder, 0755) + if err != nil { + return err + } + } + + protoPath := fmt.Sprintf("%s/%s.proto", chainFolder, data.BlockchainNameLower) + + err = blockchain.GenerateProtoFile(data.BlockchainName, goPackage, data.IsSideChain, protoPath) + if err != nil { + return err + } + } + + // Generate alembic models + + if models || full { + + modelsPath := "./moonstreamdb-v3/moonstreamdbv3" + + // read the proto file and generate the models + + err = blockchain.GenerateModelsFiles(data, modelsPath) + if err != nil { + return err + } + + } + + // Generate Go code from proto file with custom chain client + + if clientInteraface || full { + + // we need exucute that command protoc --go_out=. --go_opt=paths=source_relative $PROTO + protoFilePath := fmt.Sprintf("./blockchain/%s/%s.proto", data.BlockchainNameLower, data.BlockchainNameLower) + + log.Printf("Generating Go code from proto: %s", protoFilePath) + + // Execute protoc command + cmd := exec.Command("protoc", "--go_out=.", "--go_opt=paths=source_relative", protoFilePath) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to execute protoc command: %w", err) + } + + dirPath := filepath.Join(".", "blockchain", data.BlockchainNameLower) + blockchainNameFilePath := filepath.Join(dirPath, fmt.Sprintf("%s.go", data.BlockchainNameLower)) + + // Read and parse the template file + tmpl, parseErr := template.ParseFiles("blockchain/blockchain.go.tmpl") + if parseErr != nil { + return parseErr + } + + // Create output file + if _, statErr := os.Stat(dirPath); os.IsNotExist(statErr) { + mkdirErr := os.Mkdir(dirPath, 0775) + if mkdirErr != nil { + return mkdirErr + } + } + + outputFile, createErr := os.Create(blockchainNameFilePath) + if createErr != nil { + return createErr + } + defer outputFile.Close() + + execErr := tmpl.Execute(outputFile, data) + if execErr != nil { + return execErr + } + + log.Printf("Blockchain file generated successfully: %s", blockchainNameFilePath) + + log.Printf("Generating client interfaces for %s", chainName) + } + + // Run Alembic revision --autogenerate + + if migrations || full { + + // Change directory to moonstreamdb-v3 for alembic + err = os.Chdir("./moonstreamdb-v3") + if err != nil { + return fmt.Errorf("failed to change directory: %w", err) + } + + if alembicLabelsConfig != "" { + + // Check if database is up to date + cmd := exec.Command("alembic", "-c", alembicLabelsConfig, "upgrade", "head") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to upgrade Alembic database: %w", err) + } + + log.Println("Generated Alembic labels migration successfully.\n %s", cmd.Stdout) + + } + + // Change directory back to the root + + if alembicIndexesConfig != "" { + + // Execute Alembic revision --autogenerate + cmd := exec.Command("alembic", "-c", "alembic_indexes.dev.ini", "revision", "--autogenerate", "-m", fmt.Sprintf("add_%s_tables", data.BlockchainNameLower)) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to generate Alembic revision: %w", err) + } + // return shell output + log.Printf("Generate Alembic indexes migration successfully.\n %s", cmd.Stdout) + } + + log.Println("Alembic revision generated successfully.") + } + + // Generate deploy scripts + + if deployScripts || full { + // Create deploy scripts in deploy folder + err := blockchain.GenerateDeploy(data, "./deploy") + + if err != nil { + return err + } + + } + + // Generate bugout resources + + if createSubscriptionType { + log.Printf("Generating subscription type for %s", chainName) + } + + return nil + }, + } + + definitionsCmd.Flags().StringVar(&rpc, "rpc", "", "The RPC URL for the blockchain") + definitionsCmd.Flags().StringVar(&chainName, "chain-name", "", "The name of the blockchain") + definitionsCmd.Flags().StringVar(&outputPath, "output", "", "The path to the output file") + definitionsCmd.Flags().BoolVar(&defenitions, "definitions", false, "Generate definitions") + definitionsCmd.Flags().BoolVar(&models, "models", false, "Generate models") + definitionsCmd.Flags().BoolVar(&clientInteraface, "interfaces", false, "Generate interfaces") + definitionsCmd.Flags().BoolVar(&migrations, "migrations", false, "Generate migrations") + definitionsCmd.Flags().BoolVar(&full, "full", false, "Generate all") + definitionsCmd.Flags().BoolVar(&createSubscriptionType, "subscription", false, "Generate subscription type") + definitionsCmd.Flags().BoolVar(&deployScripts, "deploy", false, "Generate deploy scripts") + definitionsCmd.Flags().BoolVar(&L2Flag, "L2", false, "Set this flag if the chain is a Layer 2 chain") + definitionsCmd.Flags().StringVar(&alembicLabelsConfig, "alembic-labels", "", "The path to the alembic labels config file") + definitionsCmd.Flags().StringVar(&alembicIndexesConfig, "alembic-indexes", "", "The path to the alembic indexes config file") + + return definitionsCmd + +} + func StringPrompt(label string) (string, error) { var output string r := bufio.NewReader(os.Stdin) diff --git a/deploy/general-deploy.bash b/deploy/general-deploy.bash new file mode 100644 index 0000000..9a92891 --- /dev/null +++ b/deploy/general-deploy.bash @@ -0,0 +1,140 @@ +#!/usr/bin/env bash + +# Deployment script + +# Colors +C_RESET='\033[0m' +C_RED='\033[1;31m' +C_GREEN='\033[1;32m' +C_YELLOW='\033[1;33m' + +# Logs +PREFIX_INFO="${C_GREEN}[INFO]${C_RESET} [$(date +%d-%m\ %T)]" +PREFIX_WARN="${C_YELLOW}[WARN]${C_RESET} [$(date +%d-%m\ %T)]" +PREFIX_CRIT="${C_RED}[CRIT]${C_RESET} [$(date +%d-%m\ %T)]" + +# Main +AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION:-us-east-1}" +APP_DIR="${APP_DIR:-/home/ubuntu/seer}" +SECRETS_DIR="${SECRETS_DIR:-/home/ubuntu/seer-secrets}" +PARAMETERS_ENV_PATH="${SECRETS_DIR}/app.env" +SCRIPT_DIR="$(realpath $(dirname $0))" +USER_SYSTEMD_DIR="${USER_SYSTEMD_DIR:-/home/ubuntu/.config/systemd/user}" + +set -eu + +if [ ! -d "${SECRETS_DIR}" ]; then + mkdir "${SECRETS_DIR}" + echo -e "${PREFIX_WARN} Created new secrets directory" +fi + +echo +echo +echo -e "${PREFIX_INFO} Retrieving deployment parameters" +echo "# Seer environment variables" > "${PARAMETERS_ENV_PATH}" + +# List of secrets to retrieve +SECRETS=( + "MOONSTREAM_DB_V3_CONTROLLER_SEER_ACCESS_TOKEN" + "MOONSTREAM_DB_V3_INDEXES_URI" + "MOONSTREAM_NODE_ETHEREUM_A_EXTERNAL_URI" + "MOONSTREAM_NODE_SEPOLIA_A_EXTERNAL_URI" + "MOONSTREAM_NODE_POLYGON_A_EXTERNAL_URI" + "MOONSTREAM_NODE_ARBITRUM_ONE_A_EXTERNAL_URI" + "MOONSTREAM_NODE_ARBITRUM_SEPOLIA_A_EXTERNAL_URI" + "MOONSTREAM_NODE_GAME7_TESTNET_A_EXTERNAL_URI" + "MOONSTREAM_NODE_GAME7_ORBIT_ARBITRUM_SEPOLIA_A_EXTERNAL_URI" + "MOONSTREAM_NODE_XAI_A_EXTERNAL_URI" + "MOONSTREAM_NODE_XAI_SEPOLIA_A_EXTERNAL_URI" + "MOONSTREAM_NODE_MANTLE_A_EXTERNAL_URI" + "MOONSTREAM_NODE_MANTLE_SEPOLIA_A_EXTERNAL_URI" + "MOONSTREAM_NODE_IMX_ZKEVM_A_EXTERNAL_URI" + "MOONSTREAM_NODE_IMX_ZKEVM_SEPOLIA_A_EXTERNAL_URI" + "MOONSTREAM_NODE_B3_A_EXTERNAL_URI" + "MOONSTREAM_NODE_B3_SEPOLIA_A_EXTERNAL_URI" + "SEER_CRAWLER_STORAGE_BUCKET" +) + +for SECRET in "${SECRETS[@]}"; do + VALUE=$(gcloud secrets versions access latest --secret="${SECRET}") + echo "${SECRET}=${VALUE}" >> "${PARAMETERS_ENV_PATH}" +done + +echo "SEER_CRAWLER_INDEXER_LABEL=seer" >> "${PARAMETERS_ENV_PATH}" +echo "SEER_CRAWLER_STORAGE_TYPE=gcp-storage" >> "${PARAMETERS_ENV_PATH}" +echo "SEER_CRAWLER_STORAGE_PREFIX=prod" >> "${PARAMETERS_ENV_PATH}" +chmod 0640 "${PARAMETERS_ENV_PATH}" + +echo +echo +echo -e "${PREFIX_INFO} Build seer binary" +EXEC_DIR=$(pwd) +cd "${APP_DIR}" +HOME=/home/ubuntu /usr/local/go/bin/go build -o "${APP_DIR}/seer" . +chmod +x "${APP_DIR}/seer" +chown ubuntu:ubuntu "${APP_DIR}/seer" +cd "${EXEC_DIR}" + +echo +echo +echo -e "${PREFIX_INFO} Prepare user systemd directory" +if [ ! -d "${USER_SYSTEMD_DIR}" ]; then + mkdir -p "${USER_SYSTEMD_DIR}" + echo -e "${PREFIX_WARN} Created new user systemd directory" +fi + +# Function to update service files +update_service() { + local SERVICE_FILE=$1 + if [ -f "${SCRIPT_DIR}/${SERVICE_FILE}" ]; then + echo + echo + echo -e "${PREFIX_INFO} Replacing existing service with ${SERVICE_FILE}" + chmod 644 "${SCRIPT_DIR}/${SERVICE_FILE}" + cp "${SCRIPT_DIR}/${SERVICE_FILE}" "${USER_SYSTEMD_DIR}/${SERVICE_FILE}" + XDG_RUNTIME_DIR="/run/user/1000" systemctl --user daemon-reload + XDG_RUNTIME_DIR="/run/user/1000" systemctl --user restart "${SERVICE_FILE}" + else + echo -e "${PREFIX_WARN} Service file ${SERVICE_FILE} not found, skipping" + fi +} + +# Function to update historical synchronizer services and timers +update_historical_service() { + local SERVICE_FILE=$1 + local TIMER_FILE=$2 + if [ -f "${SCRIPT_DIR}/${SERVICE_FILE}" ] && [ -f "${SCRIPT_DIR}/${TIMER_FILE}" ]; then + echo + echo + echo -e "${PREFIX_INFO} Replacing existing historical synchronizer with ${SERVICE_FILE} and ${TIMER_FILE}" + chmod 644 "${SCRIPT_DIR}/${SERVICE_FILE}" "${SCRIPT_DIR}/${TIMER_FILE}" + cp "${SCRIPT_DIR}/${SERVICE_FILE}" "${USER_SYSTEMD_DIR}/${SERVICE_FILE}" + cp "${SCRIPT_DIR}/${TIMER_FILE}" "${USER_SYSTEMD_DIR}/${TIMER_FILE}" + XDG_RUNTIME_DIR="/run/user/1000" systemctl --user daemon-reload + XDG_RUNTIME_DIR="/run/user/1000" systemctl --user restart "${TIMER_FILE}" + else + echo -e "${PREFIX_WARN} Service or timer file ${SERVICE_FILE} or ${TIMER_FILE} not found, skipping" + fi +} + +# Update crawler services +for SERVICE_FILE in "${SCRIPT_DIR}"/seer-crawler-*.service; do + [ -e "$SERVICE_FILE" ] || continue + SERVICE_FILE=$(basename "${SERVICE_FILE}") + update_service "${SERVICE_FILE}" +done + +# Update synchronizer services +for SERVICE_FILE in "${SCRIPT_DIR}"/seer-synchronizer-*.service; do + [ -e "$SERVICE_FILE" ] || continue + SERVICE_FILE=$(basename "${SERVICE_FILE}") + update_service "${SERVICE_FILE}" +done + +# Update historical synchronizer services and timers +for SERVICE_FILE in "${SCRIPT_DIR}"/seer-historical-synchronizer-*.service; do + [ -e "$SERVICE_FILE" ] || continue + SERVICE_FILE=$(basename "${SERVICE_FILE}") + TIMER_FILE="${SERVICE_FILE%.service}.timer" + update_historical_service "${SERVICE_FILE}" "${TIMER_FILE}" +done diff --git a/deploy/templates/seer-crawler.service.tmpl b/deploy/templates/seer-crawler.service.tmpl new file mode 100644 index 0000000..39fb144 --- /dev/null +++ b/deploy/templates/seer-crawler.service.tmpl @@ -0,0 +1,16 @@ +{{`[Unit]`}} +Description=Seer crawler service for {{ .BlockchainName | replaceUnderscoreWithSpace }} blockchain +After=network.target +StartLimitIntervalSec=300 +StartLimitBurst=3 + +{{`[Service]`}} +WorkingDirectory=/home/ubuntu/seer +EnvironmentFile=/home/ubuntu/seer-secrets/app.env +Restart=on-failure +RestartSec=15s +ExecStart=/home/ubuntu/seer/seer crawler --chain {{ .BlockchainNameLower}} --confirmations 10 --threads 2 +SyslogIdentifier=seer-crawler-{{ .ChainDashName }} + +{{`[Install]`}} +WantedBy=multi-user.target diff --git a/deploy/templates/seer-historical-synchronizer.service.tmpl b/deploy/templates/seer-historical-synchronizer.service.tmpl new file mode 100644 index 0000000..f6d55ac --- /dev/null +++ b/deploy/templates/seer-historical-synchronizer.service.tmpl @@ -0,0 +1,16 @@ +{{`[Unit]`}} +Description=Seer historical synchronizer service for {{ .BlockchainName | replaceUnderscoreWithSpace }} blockchain +After=network.target +StartLimitIntervalSec=300 +StartLimitBurst=3 + +{{`[Service]`}} +WorkingDirectory=/home/ubuntu/seer +EnvironmentFile=/home/ubuntu/seer-secrets/app.env +Restart=on-failure +RestartSec=15s +ExecStart=/home/ubuntu/seer/seer historical-sync --auto --chain {{ .BlockchainNameLower}} +SyslogIdentifier=seer-historical-synchronizer-{{ .ChainDashName }} + +{{`[Install]`}} +WantedBy=multi-user.target diff --git a/deploy/templates/seer-historical-synchronizer.timer.tmpl b/deploy/templates/seer-historical-synchronizer.timer.tmpl new file mode 100644 index 0000000..fabca37 --- /dev/null +++ b/deploy/templates/seer-historical-synchronizer.timer.tmpl @@ -0,0 +1,9 @@ +{{ `[Unit]` }} +Description=Runs seer historical synchronizer on {{ .BlockchainName | replaceUnderscoreWithSpace }} + +{{ `[Timer]` }} +OnBootSec=60s +OnUnitActiveSec=10m + +{{ `[Install]` }} +WantedBy=timers.target \ No newline at end of file diff --git a/deploy/templates/seer-synchronizer.service.tmpl b/deploy/templates/seer-synchronizer.service.tmpl new file mode 100644 index 0000000..d37b83b --- /dev/null +++ b/deploy/templates/seer-synchronizer.service.tmpl @@ -0,0 +1,16 @@ +{{`[Unit]`}} +Description=Seer synchronizer service for {{ .BlockchainName | replaceUnderscoreWithSpace }} blockchain +After=network.target +StartLimitIntervalSec=300 +StartLimitBurst=3 + +{{`[Service]`}} +WorkingDirectory=/home/ubuntu/seer +EnvironmentFile=/home/ubuntu/seer-secrets/app.env +Restart=on-failure +RestartSec=15s +ExecStart=/home/ubuntu/seer/seer synchronizer --chain {{ .BlockchainNameLower }} +SyslogIdentifier=seer-crawler-{{ .ChainDashName }} + +{{`[Install]`}} +WantedBy=multi-user.target diff --git a/moonstreamdb-v3/.gitignore b/moonstreamdb-v3/.gitignore new file mode 100644 index 0000000..c6d1ca2 --- /dev/null +++ b/moonstreamdb-v3/.gitignore @@ -0,0 +1,201 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode + +# Envionments +.moonstream/ +.moonstreamdb/ +.moonstreamdb-v3/ +.db/ +.venv/ +.env/ + +# Environment variables +dev.env +test.env +prod.env +moonstreamdb.env +moonstreamdb-v3.env +docker.env +docker.dev.env +docker.test.dev +docker.prod.env +docker.moonstreamdb-v3.env + +.secrets/ + +# Alembic migrations +alembic.test.ini +alembic.dev.ini +alembic.prod.ini +alembic.moonstreamdb-v3.ini +alembic.docker.ini +alembic_indexes.dev.ini +alembic_indexes.test.ini +alembic_indexes.prod.ini +alembic_indexes.moonstreamdb-v3.ini + +# Schematic +srv/ +.schematic.env + +# Custom +scratch/ diff --git a/moonstreamdb-v3/.isort.cfg b/moonstreamdb-v3/.isort.cfg new file mode 100644 index 0000000..81d54de --- /dev/null +++ b/moonstreamdb-v3/.isort.cfg @@ -0,0 +1,3 @@ +[settings] +profile = black +multi_line_output = 3 \ No newline at end of file diff --git a/moonstreamdb-v3/README.md b/moonstreamdb-v3/README.md new file mode 100644 index 0000000..1f2927a --- /dev/null +++ b/moonstreamdb-v3/README.md @@ -0,0 +1 @@ +# moonstreamdb-v3 diff --git a/moonstreamdb-v3/alembic.ini b/moonstreamdb-v3/alembic.ini new file mode 100644 index 0000000..cf756ad --- /dev/null +++ b/moonstreamdb-v3/alembic.ini @@ -0,0 +1,116 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +script_location = moonstreamdbv3/alembic + +# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s +# Uncomment the line below if you want the files to be prepended with date and time +# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file +# for all available tokens +# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s + +# sys.path path, will be prepended to sys.path if present. +# defaults to the current working directory. +prepend_sys_path = . + +# timezone to use when rendering the date within the migration file +# as well as the filename. +# If specified, requires the python>=3.9 or backports.zoneinfo library. +# Any required deps can installed by adding `alembic[tz]` to the pip requirements +# string value is passed to ZoneInfo() +# leave blank for localtime +# timezone = + +# max length of characters to apply to the +# "slug" field +# truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + +# version location specification; This defaults +# to moonstreamdbv3/alembic/versions. When using multiple version +# directories, initial revisions must be specified with --version-path. +# The path separator used here should be the separator specified by "version_path_separator" below. +# version_locations = %(here)s/bar:%(here)s/bat:moonstreamdbv3/alembic/versions + +# version path separator; As mentioned above, this is the character used to split +# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep. +# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas. +# Valid values for version_path_separator are: +# +# version_path_separator = : +# version_path_separator = ; +# version_path_separator = space +version_path_separator = os # Use os.pathsep. Default configuration used for new projects. + +# set to 'true' to search source files recursively +# in each "version_locations" directory +# new in Alembic version 1.10 +# recursive_version_locations = false + +# the output encoding used when revision files +# are written from script.py.mako +# output_encoding = utf-8 + +sqlalchemy.url = driver://user:pass@localhost/dbname + + +[post_write_hooks] +# post_write_hooks defines scripts or Python functions that are run +# on newly generated revision scripts. See the documentation for further +# detail and examples + +# format using "black" - use the console_scripts runner, against the "black" entrypoint +# hooks = black +# black.type = console_scripts +# black.entrypoint = black +# black.options = -l 79 REVISION_SCRIPT_FILENAME + +# lint with attempts to fix using "ruff" - use the exec runner, execute a binary +# hooks = ruff +# ruff.type = exec +# ruff.executable = %(here)s/.venv/bin/ruff +# ruff.options = --fix REVISION_SCRIPT_FILENAME + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/moonstreamdb-v3/alembic.sample.ini b/moonstreamdb-v3/alembic.sample.ini new file mode 100644 index 0000000..055dec4 --- /dev/null +++ b/moonstreamdb-v3/alembic.sample.ini @@ -0,0 +1,116 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +script_location = moonstreamdbv3/alembic + +# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s +# Uncomment the line below if you want the files to be prepended with date and time +# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file +# for all available tokens +# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s + +# sys.path path, will be prepended to sys.path if present. +# defaults to the current working directory. +prepend_sys_path = . + +# timezone to use when rendering the date within the migration file +# as well as the filename. +# If specified, requires the python>=3.9 or backports.zoneinfo library. +# Any required deps can installed by adding `alembic[tz]` to the pip requirements +# string value is passed to ZoneInfo() +# leave blank for localtime +# timezone = + +# max length of characters to apply to the +# "slug" field +# truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + +# version location specification; This defaults +# to alembic/versions. When using multiple version +# directories, initial revisions must be specified with --version-path. +# The path separator used here should be the separator specified by "version_path_separator" below. +# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions + +# version path separator; As mentioned above, this is the character used to split +# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep. +# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas. +# Valid values for version_path_separator are: +# +# version_path_separator = : +# version_path_separator = ; +# version_path_separator = space +version_path_separator = os # Use os.pathsep. Default configuration used for new projects. + +# set to 'true' to search source files recursively +# in each "version_locations" directory +# new in Alembic version 1.10 +# recursive_version_locations = false + +# the output encoding used when revision files +# are written from script.py.mako +# output_encoding = utf-8 + +sqlalchemy.url = driver://user:pass@localhost/dbname + + +[post_write_hooks] +# post_write_hooks defines scripts or Python functions that are run +# on newly generated revision scripts. See the documentation for further +# detail and examples + +# format using "black" - use the console_scripts runner, against the "black" entrypoint +# hooks = black +# black.type = console_scripts +# black.entrypoint = black +# black.options = -l 79 REVISION_SCRIPT_FILENAME + +# lint with attempts to fix using "ruff" - use the exec runner, execute a binary +# hooks = ruff +# ruff.type = exec +# ruff.executable = %(here)s/.venv/bin/ruff +# ruff.options = --fix REVISION_SCRIPT_FILENAME + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/moonstreamdb-v3/alembic.sh b/moonstreamdb-v3/alembic.sh new file mode 100755 index 0000000..9ca8b9b --- /dev/null +++ b/moonstreamdb-v3/alembic.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +PYTHONPATH=".:$PYTHONPATH" alembic "$@" diff --git a/moonstreamdb-v3/alembic_indexes.sample.ini b/moonstreamdb-v3/alembic_indexes.sample.ini new file mode 100644 index 0000000..59ea206 --- /dev/null +++ b/moonstreamdb-v3/alembic_indexes.sample.ini @@ -0,0 +1,116 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +script_location = moonstreamdbv3/alembic_indexes + +# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s +# Uncomment the line below if you want the files to be prepended with date and time +# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file +# for all available tokens +# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s + +# sys.path path, will be prepended to sys.path if present. +# defaults to the current working directory. +prepend_sys_path = . + +# timezone to use when rendering the date within the migration file +# as well as the filename. +# If specified, requires the python>=3.9 or backports.zoneinfo library. +# Any required deps can installed by adding `alembic[tz]` to the pip requirements +# string value is passed to ZoneInfo() +# leave blank for localtime +# timezone = + +# max length of characters to apply to the +# "slug" field +# truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + +# version location specification; This defaults +# to moonstreamdbv3/alembic_indexes/versions. When using multiple version +# directories, initial revisions must be specified with --version-path. +# The path separator used here should be the separator specified by "version_path_separator" below. +# version_locations = %(here)s/bar:%(here)s/bat:moonstreamdbv3/alembic_indexes/versions + +# version path separator; As mentioned above, this is the character used to split +# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep. +# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas. +# Valid values for version_path_separator are: +# +# version_path_separator = : +# version_path_separator = ; +# version_path_separator = space +version_path_separator = os # Use os.pathsep. Default configuration used for new projects. + +# set to 'true' to search source files recursively +# in each "version_locations" directory +# new in Alembic version 1.10 +# recursive_version_locations = false + +# the output encoding used when revision files +# are written from script.py.mako +# output_encoding = utf-8 + +sqlalchemy.url = driver://user:pass@localhost/dbname_indexes + + +[post_write_hooks] +# post_write_hooks defines scripts or Python functions that are run +# on newly generated revision scripts. See the documentation for further +# detail and examples + +# format using "black" - use the console_scripts runner, against the "black" entrypoint +# hooks = black +# black.type = console_scripts +# black.entrypoint = black +# black.options = -l 79 REVISION_SCRIPT_FILENAME + +# lint with attempts to fix using "ruff" - use the exec runner, execute a binary +# hooks = ruff +# ruff.type = exec +# ruff.executable = %(here)s/.venv/bin/ruff +# ruff.options = --fix REVISION_SCRIPT_FILENAME + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/moonstreamdb-v3/moonstreamdbv3/__init__.py b/moonstreamdb-v3/moonstreamdbv3/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/README b/moonstreamdb-v3/moonstreamdbv3/alembic/README new file mode 100644 index 0000000..98e4f9c --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/README @@ -0,0 +1 @@ +Generic single-database configuration. \ No newline at end of file diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/__init__.py b/moonstreamdb-v3/moonstreamdbv3/alembic/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/env.py b/moonstreamdb-v3/moonstreamdbv3/alembic/env.py new file mode 100644 index 0000000..f857ae9 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/env.py @@ -0,0 +1,106 @@ +from logging.config import fileConfig +from alembic import context +from sqlalchemy import engine_from_config, pool +import os +import sys +import pkgutil +import importlib +from sqlalchemy.ext.declarative import DeclarativeMeta + +# Get the Alembic Config object +config = context.config + +# Interpret the config file for Python logging +if config.config_file_name is not None: + fileConfig(config.config_file_name) + +# Add project directory to sys.path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + +# Import Base and target metadata +from models.abstract_labels import Base as LabelsBase + +target_metadata = LabelsBase.metadata + + +# Dynamically import all models +def import_models(package_name): + package = importlib.import_module(package_name) + ###print(dir(package)) + for loader, module_name, is_pkg in pkgutil.walk_packages( + package.__path__, package_name + "." + ): + print(module_name) + if module_name == "__init__": + continue + importlib.import_module(module_name) + + +import_models("moonstreamdbv3.models") + + +# Collect all model classes +def get_model_classes(base): + return base.__subclasses__() + [ + cls for scls in base.__subclasses__() for cls in get_model_classes(scls) + ] + + +model_classes = get_model_classes(LabelsBase) + +# Generate set of table names +model_tablenames = { + cls.__tablename__ for cls in model_classes if hasattr(cls, "__tablename__") +} + +print(model_tablenames) + + +# Define include_symbol function +def include_symbol(tablename, schema): + return tablename in model_tablenames + + +# Run migrations offline +def run_migrations_offline(): + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, + target_metadata=target_metadata, + include_symbol=include_symbol, + literal_binds=True, + dialect_opts={"paramstyle": "named"}, + version_table="alembic_version", + include_schemas=True, + ) + + with context.begin_transaction(): + context.run_migrations() + + +# Run migrations online +def run_migrations_online(): + connectable = engine_from_config( + config.get_section(config.config_ini_section, {}), + prefix="sqlalchemy.", + poolclass=pool.NullPool, + ) + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata, + include_symbol=include_symbol, + version_table="alembic_version", + include_schemas=True, + ) + + with context.begin_transaction(): + context.run_migrations() + + +# Determine if running offline or online +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/script.py.mako b/moonstreamdb-v3/moonstreamdbv3/alembic/script.py.mako new file mode 100644 index 0000000..fbc4b07 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/script.py.mako @@ -0,0 +1,26 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision: str = ${repr(up_revision)} +down_revision: Union[str, None] = ${repr(down_revision)} +branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)} +depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)} + + +def upgrade() -> None: + ${upgrades if upgrades else "pass"} + + +def downgrade() -> None: + ${downgrades if downgrades else "pass"} diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/090c247f8618_seer_raw_index.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/090c247f8618_seer_raw_index.py new file mode 100644 index 0000000..4a64d7c --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/090c247f8618_seer_raw_index.py @@ -0,0 +1,605 @@ +"""seer raw index + +Revision ID: 090c247f8618 +Revises: 2e90b758090c +Create Date: 2024-07-24 14:55:15.986453 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = "090c247f8618" +down_revision: Union[str, None] = "2e90b758090c" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_index( + "uk_amoy_labels_tx_hash_log_idx_evt_raw", + "amoy_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_amoy_labels_tx_hash_tx_call_raw", + "amoy_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_arbitrum_nova_labels_tx_hash_log_idx_evt_raw", + "arbitrum_nova_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_arbitrum_nova_labels_tx_hash_tx_call_raw", + "arbitrum_nova_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_arbitrum_one_labels_tx_hash_log_idx_evt_raw", + "arbitrum_one_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_arbitrum_one_labels_tx_hash_tx_call_raw", + "arbitrum_one_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_arbitrum_sepolia_labels_tx_hash_log_idx_evt_raw", + "arbitrum_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_arbitrum_sepolia_labels_tx_hash_tx_call_raw", + "arbitrum_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_avalanche_fuji_labels_tx_hash_log_idx_evt_raw", + "avalanche_fuji_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_avalanche_fuji_labels_tx_hash_tx_call_raw", + "avalanche_fuji_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_avalanche_labels_tx_hash_log_idx_evt_raw", + "avalanche_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_avalanche_labels_tx_hash_tx_call_raw", + "avalanche_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_base_labels_tx_hash_log_idx_evt_raw", + "base_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_base_labels_tx_hash_tx_call_raw", + "base_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_blast_labels_tx_hash_log_idx_evt_raw", + "blast_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_blast_labels_tx_hash_tx_call_raw", + "blast_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_blast_sepolia_labels_tx_hash_log_idx_evt_raw", + "blast_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_blast_sepolia_labels_tx_hash_tx_call_raw", + "blast_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_ethereum_labels_tx_hash_log_idx_evt_raw", + "ethereum_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_ethereum_labels_tx_hash_tx_call_raw", + "ethereum_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_g7o_arbitrum_sepolia_labels_tx_hash_log_idx_evt_raw", + "game7_orbit_arbitrum_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_g7o_arbitrum_sepolia_labels_tx_hash_tx_call_raw", + "game7_orbit_arbitrum_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_mantle_labels_tx_hash_log_idx_evt_raw", + "mantle_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_mantle_labels_tx_hash_tx_call_raw", + "mantle_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_mantle_sepolia_labels_tx_hash_log_idx_evt_raw", + "mantle_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_mantle_sepolia_labels_tx_hash_tx_call_raw", + "mantle_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_mumbai_labels_tx_hash_log_idx_evt_raw", + "mumbai_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_mumbai_labels_tx_hash_tx_call_raw", + "mumbai_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_polygon_labels_tx_hash_log_idx_evt_raw", + "polygon_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_polygon_labels_tx_hash_tx_call_raw", + "polygon_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_proofofplay_apex_labels_tx_hash_log_idx_evt_raw", + "proofofplay_apex_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_proofofplay_apex_labels_tx_hash_tx_call_raw", + "proofofplay_apex_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_sepolia_labels_tx_hash_log_idx_evt_raw", + "sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_sepolia_labels_tx_hash_tx_call_raw", + "sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_starknet_labels_tx_hash_log_idx_evt_raw", + "starknet_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_starknet_labels_tx_hash_tx_call_raw", + "starknet_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_starknet_sepolia_labels_tx_hash_log_idx_evt_raw", + "starknet_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_starknet_sepolia_labels_tx_hash_tx_call_raw", + "starknet_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_xai_labels_tx_hash_log_idx_evt_raw", + "xai_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_xai_labels_tx_hash_tx_call_raw", + "xai_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_xai_sepolia_labels_tx_hash_log_idx_evt_raw", + "xai_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_xai_sepolia_labels_tx_hash_tx_call_raw", + "xai_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_xdai_labels_tx_hash_log_idx_evt_raw", + "xdai_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_xdai_labels_tx_hash_tx_call_raw", + "xdai_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_zksync_era_labels_tx_hash_log_idx_evt_raw", + "zksync_era_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_zksync_era_labels_tx_hash_tx_call_raw", + "zksync_era_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_index( + "uk_zksync_era_sepolia_labels_tx_hash_log_idx_evt_raw", + "zksync_era_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_zksync_era_sepolia_labels_tx_hash_tx_call_raw", + "zksync_era_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + "uk_zksync_era_sepolia_labels_tx_hash_tx_call_raw", + table_name="zksync_era_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_zksync_era_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="zksync_era_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_zksync_era_labels_tx_hash_tx_call_raw", + table_name="zksync_era_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_zksync_era_labels_tx_hash_log_idx_evt_raw", + table_name="zksync_era_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_xdai_labels_tx_hash_tx_call_raw", + table_name="xdai_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_xdai_labels_tx_hash_log_idx_evt_raw", + table_name="xdai_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_xai_sepolia_labels_tx_hash_tx_call_raw", + table_name="xai_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_xai_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="xai_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_xai_labels_tx_hash_tx_call_raw", + table_name="xai_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_xai_labels_tx_hash_log_idx_evt_raw", + table_name="xai_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_starknet_sepolia_labels_tx_hash_tx_call_raw", + table_name="starknet_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_starknet_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="starknet_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_starknet_labels_tx_hash_tx_call_raw", + table_name="starknet_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_starknet_labels_tx_hash_log_idx_evt_raw", + table_name="starknet_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_sepolia_labels_tx_hash_tx_call_raw", + table_name="sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_proofofplay_apex_labels_tx_hash_tx_call_raw", + table_name="proofofplay_apex_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_proofofplay_apex_labels_tx_hash_log_idx_evt_raw", + table_name="proofofplay_apex_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_polygon_labels_tx_hash_tx_call_raw", + table_name="polygon_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_polygon_labels_tx_hash_log_idx_evt_raw", + table_name="polygon_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_mumbai_labels_tx_hash_tx_call_raw", + table_name="mumbai_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_mumbai_labels_tx_hash_log_idx_evt_raw", + table_name="mumbai_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_mantle_sepolia_labels_tx_hash_tx_call_raw", + table_name="mantle_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_mantle_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="mantle_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_mantle_labels_tx_hash_tx_call_raw", + table_name="mantle_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_mantle_labels_tx_hash_log_idx_evt_raw", + table_name="mantle_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_g7o_arbitrum_sepolia_labels_tx_hash_tx_call_raw", + table_name="game7_orbit_arbitrum_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_g7o_arbitrum_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="game7_orbit_arbitrum_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_ethereum_labels_tx_hash_tx_call_raw", + table_name="ethereum_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_ethereum_labels_tx_hash_log_idx_evt_raw", + table_name="ethereum_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_blast_sepolia_labels_tx_hash_tx_call_raw", + table_name="blast_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_blast_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="blast_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_blast_labels_tx_hash_tx_call_raw", + table_name="blast_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_blast_labels_tx_hash_log_idx_evt_raw", + table_name="blast_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_base_labels_tx_hash_tx_call_raw", + table_name="base_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_base_labels_tx_hash_log_idx_evt_raw", + table_name="base_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_avalanche_labels_tx_hash_tx_call_raw", + table_name="avalanche_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_avalanche_labels_tx_hash_log_idx_evt_raw", + table_name="avalanche_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_avalanche_fuji_labels_tx_hash_tx_call_raw", + table_name="avalanche_fuji_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_avalanche_fuji_labels_tx_hash_log_idx_evt_raw", + table_name="avalanche_fuji_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_arbitrum_sepolia_labels_tx_hash_tx_call_raw", + table_name="arbitrum_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_arbitrum_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="arbitrum_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_arbitrum_one_labels_tx_hash_tx_call_raw", + table_name="arbitrum_one_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_arbitrum_one_labels_tx_hash_log_idx_evt_raw", + table_name="arbitrum_one_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_arbitrum_nova_labels_tx_hash_tx_call_raw", + table_name="arbitrum_nova_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_arbitrum_nova_labels_tx_hash_log_idx_evt_raw", + table_name="arbitrum_nova_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_amoy_labels_tx_hash_tx_call_raw", + table_name="amoy_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_amoy_labels_tx_hash_log_idx_evt_raw", + table_name="amoy_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/1d53afc1eff4_add_b3.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/1d53afc1eff4_add_b3.py new file mode 100644 index 0000000..7145b4b --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/1d53afc1eff4_add_b3.py @@ -0,0 +1,307 @@ +"""add-b3 + +Revision ID: 1d53afc1eff4 +Revises: db9559f9566c +Create Date: 2024-09-11 14:19:12.762655 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = "1d53afc1eff4" +down_revision: Union[str, None] = "db9559f9566c" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "b3_labels", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("label", sa.VARCHAR(length=256), nullable=False), + sa.Column("transaction_hash", sa.VARCHAR(length=128), nullable=False), + sa.Column("log_index", sa.Integer(), nullable=True), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("caller_address", sa.LargeBinary(), nullable=True), + sa.Column("origin_address", sa.LargeBinary(), nullable=True), + sa.Column("address", sa.LargeBinary(), nullable=False), + sa.Column("label_name", sa.Text(), nullable=True), + sa.Column("label_type", sa.VARCHAR(length=64), nullable=True), + sa.Column("label_data", postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column( + "created_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_labels")), + sa.UniqueConstraint("id", name=op.f("uq_b3_labels_id")), + ) + op.create_index( + "ix_b3_labels_addr_block_num", + "b3_labels", + ["address", "block_number"], + unique=False, + ) + op.create_index( + "ix_b3_labels_addr_block_ts", + "b3_labels", + ["address", "block_timestamp"], + unique=False, + ) + op.create_index( + op.f("ix_b3_labels_address"), "b3_labels", ["address"], unique=False + ) + op.create_index( + op.f("ix_b3_labels_block_number"), "b3_labels", ["block_number"], unique=False + ) + op.create_index( + op.f("ix_b3_labels_caller_address"), + "b3_labels", + ["caller_address"], + unique=False, + ) + op.create_index(op.f("ix_b3_labels_label"), "b3_labels", ["label"], unique=False) + op.create_index( + op.f("ix_b3_labels_label_name"), "b3_labels", ["label_name"], unique=False + ) + op.create_index( + op.f("ix_b3_labels_label_type"), "b3_labels", ["label_type"], unique=False + ) + op.create_index( + op.f("ix_b3_labels_origin_address"), + "b3_labels", + ["origin_address"], + unique=False, + ) + op.create_index( + op.f("ix_b3_labels_transaction_hash"), + "b3_labels", + ["transaction_hash"], + unique=False, + ) + op.create_index( + "uk_b3_labels_tx_hash_log_idx_evt", + "b3_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.create_index( + "uk_b3_labels_tx_hash_log_idx_evt_raw", + "b3_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_b3_labels_tx_hash_tx_call", + "b3_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.create_index( + "uk_b3_labels_tx_hash_tx_call_raw", + "b3_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_table( + "b3_sepolia_labels", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("label", sa.VARCHAR(length=256), nullable=False), + sa.Column("transaction_hash", sa.VARCHAR(length=128), nullable=False), + sa.Column("log_index", sa.Integer(), nullable=True), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("caller_address", sa.LargeBinary(), nullable=True), + sa.Column("origin_address", sa.LargeBinary(), nullable=True), + sa.Column("address", sa.LargeBinary(), nullable=False), + sa.Column("label_name", sa.Text(), nullable=True), + sa.Column("label_type", sa.VARCHAR(length=64), nullable=True), + sa.Column("label_data", postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column( + "created_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_sepolia_labels")), + sa.UniqueConstraint("id", name=op.f("uq_b3_sepolia_labels_id")), + ) + op.create_index( + "ix_b3_sepolia_labels_addr_block_num", + "b3_sepolia_labels", + ["address", "block_number"], + unique=False, + ) + op.create_index( + "ix_b3_sepolia_labels_addr_block_ts", + "b3_sepolia_labels", + ["address", "block_timestamp"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_address"), + "b3_sepolia_labels", + ["address"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_block_number"), + "b3_sepolia_labels", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_caller_address"), + "b3_sepolia_labels", + ["caller_address"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_label"), "b3_sepolia_labels", ["label"], unique=False + ) + op.create_index( + op.f("ix_b3_sepolia_labels_label_name"), + "b3_sepolia_labels", + ["label_name"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_label_type"), + "b3_sepolia_labels", + ["label_type"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_origin_address"), + "b3_sepolia_labels", + ["origin_address"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_transaction_hash"), + "b3_sepolia_labels", + ["transaction_hash"], + unique=False, + ) + op.create_index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt", + "b3_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.create_index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt_raw", + "b3_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_b3_sepolia_labels_tx_hash_tx_call", + "b3_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.create_index( + "uk_b3_sepolia_labels_tx_hash_tx_call_raw", + "b3_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + "uk_b3_sepolia_labels_tx_hash_tx_call_raw", + table_name="b3_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_b3_sepolia_labels_tx_hash_tx_call", + table_name="b3_sepolia_labels", + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.drop_index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="b3_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt", + table_name="b3_sepolia_labels", + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_transaction_hash"), table_name="b3_sepolia_labels" + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_origin_address"), table_name="b3_sepolia_labels" + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_label_type"), table_name="b3_sepolia_labels" + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_label_name"), table_name="b3_sepolia_labels" + ) + op.drop_index(op.f("ix_b3_sepolia_labels_label"), table_name="b3_sepolia_labels") + op.drop_index( + op.f("ix_b3_sepolia_labels_caller_address"), table_name="b3_sepolia_labels" + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_block_number"), table_name="b3_sepolia_labels" + ) + op.drop_index(op.f("ix_b3_sepolia_labels_address"), table_name="b3_sepolia_labels") + op.drop_index("ix_b3_sepolia_labels_addr_block_ts", table_name="b3_sepolia_labels") + op.drop_index("ix_b3_sepolia_labels_addr_block_num", table_name="b3_sepolia_labels") + op.drop_table("b3_sepolia_labels") + op.drop_index( + "uk_b3_labels_tx_hash_tx_call_raw", + table_name="b3_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_b3_labels_tx_hash_tx_call", + table_name="b3_labels", + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.drop_index( + "uk_b3_labels_tx_hash_log_idx_evt_raw", + table_name="b3_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_b3_labels_tx_hash_log_idx_evt", + table_name="b3_labels", + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.drop_index(op.f("ix_b3_labels_transaction_hash"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_origin_address"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_label_type"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_label_name"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_label"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_caller_address"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_block_number"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_address"), table_name="b3_labels") + op.drop_index("ix_b3_labels_addr_block_ts", table_name="b3_labels") + op.drop_index("ix_b3_labels_addr_block_num", table_name="b3_labels") + op.drop_table("b3_labels") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/211646463e9f_immutable_zkevm_with_it_s_sepolia_.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/211646463e9f_immutable_zkevm_with_it_s_sepolia_.py new file mode 100644 index 0000000..d6a3b73 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/211646463e9f_immutable_zkevm_with_it_s_sepolia_.py @@ -0,0 +1,122 @@ +"""Immutable zkEvm with it's sepolia blockchains + +Revision ID: 211646463e9f +Revises: 090c247f8618 +Create Date: 2024-07-25 14:14:41.548326 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = '211646463e9f' +down_revision: Union[str, None] = '090c247f8618' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('imx_zkevm_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.LargeBinary(), nullable=True), + sa.Column('origin_address', sa.LargeBinary(), nullable=True), + sa.Column('address', sa.LargeBinary(), nullable=False), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_imx_zkevm_labels')), + sa.UniqueConstraint('id', name=op.f('uq_imx_zkevm_labels_id')) + ) + op.create_index('ix_imx_zkevm_labels_addr_block_num', 'imx_zkevm_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_imx_zkevm_labels_addr_block_ts', 'imx_zkevm_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_address'), 'imx_zkevm_labels', ['address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_block_number'), 'imx_zkevm_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_caller_address'), 'imx_zkevm_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_label'), 'imx_zkevm_labels', ['label'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_label_name'), 'imx_zkevm_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_label_type'), 'imx_zkevm_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_origin_address'), 'imx_zkevm_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_transaction_hash'), 'imx_zkevm_labels', ['transaction_hash'], unique=False) + op.create_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt', 'imx_zkevm_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt_raw', 'imx_zkevm_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.create_index('uk_imx_zkevm_labels_tx_hash_tx_call', 'imx_zkevm_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.create_index('uk_imx_zkevm_labels_tx_hash_tx_call_raw', 'imx_zkevm_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'")) + op.create_table('imx_zkevm_sepolia_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.LargeBinary(), nullable=True), + sa.Column('origin_address', sa.LargeBinary(), nullable=True), + sa.Column('address', sa.LargeBinary(), nullable=False), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_imx_zkevm_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_imx_zkevm_sepolia_labels_id')) + ) + op.create_index('ix_imx_zkevm_sepolia_labels_addr_block_num', 'imx_zkevm_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_imx_zkevm_sepolia_labels_addr_block_ts', 'imx_zkevm_sepolia_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_address'), 'imx_zkevm_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_block_number'), 'imx_zkevm_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_caller_address'), 'imx_zkevm_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_label'), 'imx_zkevm_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_label_name'), 'imx_zkevm_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_label_type'), 'imx_zkevm_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_origin_address'), 'imx_zkevm_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_transaction_hash'), 'imx_zkevm_sepolia_labels', ['transaction_hash'], unique=False) + op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt', 'imx_zkevm_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt_raw', 'imx_zkevm_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call', 'imx_zkevm_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call_raw', 'imx_zkevm_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'")) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call_raw', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'")) + op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt_raw', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_transaction_hash'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_origin_address'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_label_type'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_label_name'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_label'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_caller_address'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_block_number'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_address'), table_name='imx_zkevm_sepolia_labels') + op.drop_index('ix_imx_zkevm_sepolia_labels_addr_block_ts', table_name='imx_zkevm_sepolia_labels') + op.drop_index('ix_imx_zkevm_sepolia_labels_addr_block_num', table_name='imx_zkevm_sepolia_labels') + op.drop_table('imx_zkevm_sepolia_labels') + op.drop_index('uk_imx_zkevm_labels_tx_hash_tx_call_raw', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'")) + op.drop_index('uk_imx_zkevm_labels_tx_hash_tx_call', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt_raw', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.drop_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index(op.f('ix_imx_zkevm_labels_transaction_hash'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_origin_address'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_label_type'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_label_name'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_label'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_caller_address'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_block_number'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_address'), table_name='imx_zkevm_labels') + op.drop_index('ix_imx_zkevm_labels_addr_block_ts', table_name='imx_zkevm_labels') + op.drop_index('ix_imx_zkevm_labels_addr_block_num', table_name='imx_zkevm_labels') + op.drop_table('imx_zkevm_labels') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/2e90b758090c_bytea_address_in_labels.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/2e90b758090c_bytea_address_in_labels.py new file mode 100644 index 0000000..6273026 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/2e90b758090c_bytea_address_in_labels.py @@ -0,0 +1,749 @@ +"""Bytea address in labels + +Revision ID: 2e90b758090c +Revises: 792ca9c4722c +Create Date: 2024-07-15 17:38:36.529835 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "2e90b758090c" +down_revision: Union[str, None] = "9ca39b11e12a" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.execute( + "ALTER TABLE amoy_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE amoy_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE amoy_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE arbitrum_nova_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE arbitrum_nova_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE arbitrum_nova_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE arbitrum_one_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE arbitrum_one_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE arbitrum_one_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE arbitrum_sepolia_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE arbitrum_sepolia_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE arbitrum_sepolia_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE avalanche_fuji_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE avalanche_fuji_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE avalanche_fuji_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE avalanche_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE avalanche_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE avalanche_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE base_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE base_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE base_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE blast_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE blast_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE blast_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE blast_sepolia_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE blast_sepolia_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE blast_sepolia_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE ethereum_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE ethereum_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE ethereum_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE game7_orbit_arbitrum_sepolia_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE game7_orbit_arbitrum_sepolia_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE game7_orbit_arbitrum_sepolia_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE mantle_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE mantle_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE mantle_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE mantle_sepolia_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE mantle_sepolia_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE mantle_sepolia_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE mumbai_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE mumbai_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE mumbai_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE polygon_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE polygon_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE polygon_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE proofofplay_apex_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE proofofplay_apex_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE proofofplay_apex_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE sepolia_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE sepolia_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE sepolia_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE starknet_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE starknet_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE starknet_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE starknet_sepolia_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE starknet_sepolia_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE starknet_sepolia_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE xai_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE xai_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE xai_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE xai_sepolia_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE xai_sepolia_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE xai_sepolia_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE xdai_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE xdai_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE xdai_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE zksync_era_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE zksync_era_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE zksync_era_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + op.execute( + "ALTER TABLE zksync_era_sepolia_labels ALTER COLUMN caller_address TYPE bytea USING caller_address::bytea" + ) + op.execute( + "ALTER TABLE zksync_era_sepolia_labels ALTER COLUMN origin_address TYPE bytea USING origin_address::bytea" + ) + op.execute( + "ALTER TABLE zksync_era_sepolia_labels ALTER COLUMN address TYPE bytea USING address::bytea" + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "zksync_era_sepolia_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "zksync_era_sepolia_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "zksync_era_sepolia_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "zksync_era_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "zksync_era_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "zksync_era_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "xdai_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "xdai_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "xdai_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "xai_sepolia_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "xai_sepolia_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "xai_sepolia_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "xai_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "xai_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "xai_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "starknet_sepolia_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "starknet_sepolia_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "starknet_sepolia_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "starknet_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "starknet_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "starknet_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "sepolia_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "sepolia_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "sepolia_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "proofofplay_apex_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "proofofplay_apex_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "proofofplay_apex_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "polygon_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "polygon_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "polygon_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "mumbai_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "mumbai_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "mumbai_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "mantle_sepolia_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "mantle_sepolia_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "mantle_sepolia_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "mantle_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "mantle_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "mantle_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "game7_orbit_arbitrum_sepolia_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "game7_orbit_arbitrum_sepolia_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "game7_orbit_arbitrum_sepolia_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "ethereum_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "ethereum_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "ethereum_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "blast_sepolia_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "blast_sepolia_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "blast_sepolia_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "blast_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "blast_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "blast_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "base_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "base_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "base_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "avalanche_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "avalanche_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "avalanche_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "avalanche_fuji_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "avalanche_fuji_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "avalanche_fuji_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "arbitrum_sepolia_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "arbitrum_sepolia_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "arbitrum_sepolia_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "arbitrum_one_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "arbitrum_one_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "arbitrum_one_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "arbitrum_nova_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "arbitrum_nova_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "arbitrum_nova_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "amoy_labels", + "address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + nullable=True, + ) + op.alter_column( + "amoy_labels", + "origin_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + op.alter_column( + "amoy_labels", + "caller_address", + existing_type=sa.LargeBinary(), + type_=sa.VARCHAR(length=64), + existing_nullable=True, + ) + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/994e614b5500_tables_initial_generation.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/994e614b5500_tables_initial_generation.py new file mode 100644 index 0000000..b902c58 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/994e614b5500_tables_initial_generation.py @@ -0,0 +1,620 @@ +"""Tables initial generation + +Revision ID: 994e614b5500 +Revises: +Create Date: 2024-03-14 07:03:35.586195 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = '994e614b5500' +down_revision: Union[str, None] = None +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('arbitrum_nova_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_arbitrum_nova_labels')), + sa.UniqueConstraint('id', name=op.f('uq_arbitrum_nova_labels_id')), + ) + op.create_index('ix_arbitrum_nova_labels_addr_block_num', 'arbitrum_nova_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_address'), 'arbitrum_nova_labels', ['address'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_block_number'), 'arbitrum_nova_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_caller_address'), 'arbitrum_nova_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_label'), 'arbitrum_nova_labels', ['label'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_label_name'), 'arbitrum_nova_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_label_type'), 'arbitrum_nova_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_origin_address'), 'arbitrum_nova_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_transaction_hash'), 'arbitrum_nova_labels', ['transaction_hash'], unique=False) + op.create_table('arbitrum_sepolia_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_arbitrum_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_arbitrum_sepolia_labels_id')) + ) + op.create_index('ix_arbitrum_sepolia_labels_addr_block_num', 'arbitrum_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_address'), 'arbitrum_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_block_number'), 'arbitrum_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_caller_address'), 'arbitrum_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_label'), 'arbitrum_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_label_name'), 'arbitrum_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_label_type'), 'arbitrum_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_origin_address'), 'arbitrum_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_transaction_hash'), 'arbitrum_sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('base_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_base_labels')), + sa.UniqueConstraint('id', name=op.f('uq_base_labels_id')) + ) + op.create_index('ix_base_labels_addr_block_num', 'base_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_base_labels_address'), 'base_labels', ['address'], unique=False) + op.create_index(op.f('ix_base_labels_block_number'), 'base_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_base_labels_caller_address'), 'base_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_base_labels_label'), 'base_labels', ['label'], unique=False) + op.create_index(op.f('ix_base_labels_label_name'), 'base_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_base_labels_label_type'), 'base_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_base_labels_origin_address'), 'base_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_base_labels_transaction_hash'), 'base_labels', ['transaction_hash'], unique=False) + op.create_table('ethereum_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_ethereum_labels')), + sa.UniqueConstraint('id', name=op.f('uq_ethereum_labels_id')) + ) + op.create_index('ix_ethereum_labels_addr_block_num', 'ethereum_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_ethereum_labels_address'), 'ethereum_labels', ['address'], unique=False) + op.create_index(op.f('ix_ethereum_labels_block_number'), 'ethereum_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_ethereum_labels_caller_address'), 'ethereum_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_ethereum_labels_label'), 'ethereum_labels', ['label'], unique=False) + op.create_index(op.f('ix_ethereum_labels_label_name'), 'ethereum_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_ethereum_labels_label_type'), 'ethereum_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_ethereum_labels_origin_address'), 'ethereum_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_ethereum_labels_transaction_hash'), 'ethereum_labels', ['transaction_hash'], unique=False) + op.create_table('mumbai_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_mumbai_labels')), + sa.UniqueConstraint('id', name=op.f('uq_mumbai_labels_id')) + ) + op.create_index('ix_mumbai_labels_addr_block_num', 'mumbai_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_mumbai_labels_address'), 'mumbai_labels', ['address'], unique=False) + op.create_index(op.f('ix_mumbai_labels_block_number'), 'mumbai_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_mumbai_labels_caller_address'), 'mumbai_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_mumbai_labels_label'), 'mumbai_labels', ['label'], unique=False) + op.create_index(op.f('ix_mumbai_labels_label_name'), 'mumbai_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_mumbai_labels_label_type'), 'mumbai_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_mumbai_labels_origin_address'), 'mumbai_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_mumbai_labels_transaction_hash'), 'mumbai_labels', ['transaction_hash'], unique=False) + op.create_table('polygon_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_polygon_labels')), + sa.UniqueConstraint('id', name=op.f('uq_polygon_labels_id')) + ) + op.create_index('ix_polygon_labels_addr_block_num', 'polygon_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_polygon_labels_address'), 'polygon_labels', ['address'], unique=False) + op.create_index(op.f('ix_polygon_labels_block_number'), 'polygon_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_polygon_labels_caller_address'), 'polygon_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_polygon_labels_label'), 'polygon_labels', ['label'], unique=False) + op.create_index(op.f('ix_polygon_labels_label_name'), 'polygon_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_polygon_labels_label_type'), 'polygon_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_polygon_labels_origin_address'), 'polygon_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_polygon_labels_transaction_hash'), 'polygon_labels', ['transaction_hash'], unique=False) + op.create_table('sepolia_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_sepolia_labels_id')) + ) + op.create_index('ix_sepolia_labels_addr_block_num', 'sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_sepolia_labels_address'), 'sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_sepolia_labels_block_number'), 'sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_sepolia_labels_caller_address'), 'sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_sepolia_labels_label'), 'sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_sepolia_labels_label_name'), 'sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_sepolia_labels_label_type'), 'sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_sepolia_labels_origin_address'), 'sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_sepolia_labels_transaction_hash'), 'sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('xai_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_xai_labels')), + sa.UniqueConstraint('id', name=op.f('uq_xai_labels_id')) + ) + op.create_index('ix_xai_labels_addr_block_num', 'xai_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_xai_labels_address'), 'xai_labels', ['address'], unique=False) + op.create_index(op.f('ix_xai_labels_block_number'), 'xai_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_xai_labels_caller_address'), 'xai_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_xai_labels_label'), 'xai_labels', ['label'], unique=False) + op.create_index(op.f('ix_xai_labels_label_name'), 'xai_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_xai_labels_label_type'), 'xai_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_xai_labels_origin_address'), 'xai_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_xai_labels_transaction_hash'), 'xai_labels', ['transaction_hash'], unique=False) + op.create_table('xai_sepolia_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_xai_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_xai_sepolia_labels_id')) + ) + op.create_index('ix_xai_sepolia_labels_addr_block_num', 'xai_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_address'), 'xai_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_block_number'), 'xai_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_caller_address'), 'xai_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_label'), 'xai_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_label_name'), 'xai_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_label_type'), 'xai_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_origin_address'), 'xai_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_transaction_hash'), 'xai_sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('xdai_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_xdai_labels')), + sa.UniqueConstraint('id', name=op.f('uq_xdai_labels_id')) + ) + op.create_index('ix_xdai_labels_addr_block_num', 'xdai_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_xdai_labels_address'), 'xdai_labels', ['address'], unique=False) + op.create_index(op.f('ix_xdai_labels_block_number'), 'xdai_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_xdai_labels_caller_address'), 'xdai_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_xdai_labels_label'), 'xdai_labels', ['label'], unique=False) + op.create_index(op.f('ix_xdai_labels_label_name'), 'xdai_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_xdai_labels_label_type'), 'xdai_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_xdai_labels_origin_address'), 'xdai_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_xdai_labels_transaction_hash'), 'xdai_labels', ['transaction_hash'], unique=False) + op.create_table('zksync_era_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_zksync_era_labels')), + sa.UniqueConstraint('id', name=op.f('uq_zksync_era_labels_id')) + ) + op.create_index('ix_zksync_era_labels_addr_block_num', 'zksync_era_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_address'), 'zksync_era_labels', ['address'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_block_number'), 'zksync_era_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_caller_address'), 'zksync_era_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_label'), 'zksync_era_labels', ['label'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_label_name'), 'zksync_era_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_label_type'), 'zksync_era_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_origin_address'), 'zksync_era_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_transaction_hash'), 'zksync_era_labels', ['transaction_hash'], unique=False) + op.create_table('zksync_era_sepolia_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_zksync_era_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_zksync_era_sepolia_labels_id')) + ) + op.create_index('ix_zksync_era_sepolia_labels_addr_block_num', 'zksync_era_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_address'), 'zksync_era_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_block_number'), 'zksync_era_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_caller_address'), 'zksync_era_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_label'), 'zksync_era_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_label_name'), 'zksync_era_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_label_type'), 'zksync_era_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_origin_address'), 'zksync_era_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_transaction_hash'), 'zksync_era_sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('avalanche_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_avalanche_labels')), + sa.UniqueConstraint('id', name=op.f('uq_avalanche_labels_id')) + ) + op.create_index('ix_avalanche_labels_addr_block_num', 'avalanche_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_avalanche_labels_address'), 'avalanche_labels', ['address'], unique=False) + op.create_index(op.f('ix_avalanche_labels_block_number'), 'avalanche_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_avalanche_labels_caller_address'), 'avalanche_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_avalanche_labels_label'), 'avalanche_labels', ['label'], unique=False) + op.create_index(op.f('ix_avalanche_labels_label_name'), 'avalanche_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_avalanche_labels_label_type'), 'avalanche_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_avalanche_labels_origin_address'), 'avalanche_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_avalanche_labels_transaction_hash'), 'avalanche_labels', ['transaction_hash'], unique=False) + op.create_table('avalanche_fuji_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_avalanche_fuji_labels')), + sa.UniqueConstraint('id', name=op.f('uq_avalanche_fuji_labels_id')) + ) + op.create_index('ix_avalanche_fuji_labels_addr_block_num', 'avalanche_fuji_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_address'), 'avalanche_fuji_labels', ['address'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_block_number'), 'avalanche_fuji_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_caller_address'), 'avalanche_fuji_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_label'), 'avalanche_fuji_labels', ['label'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_label_name'), 'avalanche_fuji_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_label_type'), 'avalanche_fuji_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_origin_address'), 'avalanche_fuji_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_transaction_hash'), 'avalanche_fuji_labels', ['transaction_hash'], unique=False) + op.create_table('starknet_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_starknet_labels')), + sa.UniqueConstraint('id', name=op.f('uq_starknet_labels_id')) + ) + op.create_index('ix_starknet_labels_addr_block_num', 'starknet_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_starknet_labels_address'), 'starknet_labels', ['address'], unique=False) + op.create_index(op.f('ix_starknet_labels_block_number'), 'starknet_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_starknet_labels_caller_address'), 'starknet_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_starknet_labels_label'), 'starknet_labels', ['label'], unique=False) + op.create_index(op.f('ix_starknet_labels_label_name'), 'starknet_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_starknet_labels_label_type'), 'starknet_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_starknet_labels_origin_address'), 'starknet_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_starknet_labels_transaction_hash'), 'starknet_labels', ['transaction_hash'], unique=False) + op.create_table('starknet_sepolia_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_starknet_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_starknet_sepolia_labels_id')) + ) + op.create_index('ix_starknet_sepolia_labels_addr_block_num', 'starknet_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_address'), 'starknet_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_block_number'), 'starknet_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_caller_address'), 'starknet_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_label'), 'starknet_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_label_name'), 'starknet_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_label_type'), 'starknet_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_origin_address'), 'starknet_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_transaction_hash'), 'starknet_sepolia_labels', ['transaction_hash'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_zksync_era_sepolia_labels_transaction_hash'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_origin_address'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_label_type'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_label_name'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_label'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_caller_address'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_block_number'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_address'), table_name='zksync_era_sepolia_labels') + op.drop_index('ix_zksync_era_sepolia_labels_addr_block_num', table_name='zksync_era_sepolia_labels') + op.drop_table('zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_labels_transaction_hash'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_origin_address'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_label_type'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_label_name'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_label'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_caller_address'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_block_number'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_address'), table_name='zksync_era_labels') + op.drop_index('ix_zksync_era_labels_addr_block_num', table_name='zksync_era_labels') + op.drop_table('zksync_era_labels') + op.drop_index(op.f('ix_xdai_labels_transaction_hash'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_origin_address'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_label_type'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_label_name'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_label'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_caller_address'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_block_number'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_address'), table_name='xdai_labels') + op.drop_index('ix_xdai_labels_addr_block_num', table_name='xdai_labels') + op.drop_table('xdai_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_transaction_hash'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_origin_address'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_label_type'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_label_name'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_label'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_caller_address'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_block_number'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_address'), table_name='xai_sepolia_labels') + op.drop_index('ix_xai_sepolia_labels_addr_block_num', table_name='xai_sepolia_labels') + op.drop_table('xai_sepolia_labels') + op.drop_index(op.f('ix_xai_labels_transaction_hash'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_origin_address'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_label_type'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_label_name'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_label'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_caller_address'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_block_number'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_address'), table_name='xai_labels') + op.drop_index('ix_xai_labels_addr_block_num', table_name='xai_labels') + op.drop_table('xai_labels') + op.drop_index(op.f('ix_sepolia_labels_transaction_hash'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_origin_address'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_label_type'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_label_name'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_label'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_caller_address'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_block_number'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_address'), table_name='sepolia_labels') + op.drop_index('ix_sepolia_labels_addr_block_num', table_name='sepolia_labels') + op.drop_table('sepolia_labels') + op.drop_index(op.f('ix_polygon_labels_transaction_hash'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_origin_address'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_label_type'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_label_name'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_label'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_caller_address'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_block_number'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_address'), table_name='polygon_labels') + op.drop_index('ix_polygon_labels_addr_block_num', table_name='polygon_labels') + op.drop_table('polygon_labels') + op.drop_index(op.f('ix_mumbai_labels_transaction_hash'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_origin_address'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_label_type'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_label_name'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_label'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_caller_address'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_block_number'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_address'), table_name='mumbai_labels') + op.drop_index('ix_mumbai_labels_addr_block_num', table_name='mumbai_labels') + op.drop_table('mumbai_labels') + op.drop_index(op.f('ix_ethereum_labels_transaction_hash'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_origin_address'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_label_type'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_label_name'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_label'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_caller_address'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_block_number'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_address'), table_name='ethereum_labels') + op.drop_index('ix_ethereum_labels_addr_block_num', table_name='ethereum_labels') + op.drop_table('ethereum_labels') + op.drop_index(op.f('ix_base_labels_transaction_hash'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_origin_address'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_label_type'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_label_name'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_label'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_caller_address'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_block_number'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_address'), table_name='base_labels') + op.drop_index('ix_base_labels_addr_block_num', table_name='base_labels') + op.drop_table('base_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_transaction_hash'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_origin_address'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_label_type'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_label_name'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_label'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_caller_address'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_block_number'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_address'), table_name='arbitrum_sepolia_labels') + op.drop_index('ix_arbitrum_sepolia_labels_addr_block_num', table_name='arbitrum_sepolia_labels') + op.drop_table('arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_transaction_hash'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_origin_address'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_label_type'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_label_name'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_label'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_caller_address'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_block_number'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_address'), table_name='arbitrum_nova_labels') + op.drop_index('ix_arbitrum_nova_labels_addr_block_num', table_name='arbitrum_nova_labels') + op.drop_table('arbitrum_nova_labels') + op.drop_index(op.f('ix_avalanche_labels_transaction_hash'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_origin_address'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_label_type'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_label_name'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_label'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_caller_address'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_block_number'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_address'), table_name='avalanche_labels') + op.drop_index('ix_avalanche_labels_addr_block_num', table_name='avalanche_labels') + op.drop_table('avalanche_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_transaction_hash'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_origin_address'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_label_type'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_label_name'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_label'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_caller_address'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_block_number'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_address'), table_name='avalanche_fuji_labels') + op.drop_index('ix_avalanche_fuji_labels_addr_block_num', table_name='avalanche_fuji_labels') + op.drop_table('avalanche_fuji_labels') + op.drop_index(op.f('ix_starknet_labels_transaction_hash'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_origin_address'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_label_type'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_label_name'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_label'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_caller_address'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_block_number'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_address'), table_name='starknet_labels') + op.drop_index('ix_starknet_labels_addr_block_num', table_name='starknet_labels') + op.drop_table('starknet_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_transaction_hash'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_origin_address'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_label_type'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_label_name'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_label'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_caller_address'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_block_number'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_address'), table_name='starknet_sepolia_labels') + op.drop_index('ix_starknet_sepolia_labels_addr_block_num', table_name='starknet_sepolia_labels') + op.drop_table('starknet_sepolia_labels') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/9ca39b11e12a_game7_orbit_and_mantle_blockchain_models.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/9ca39b11e12a_game7_orbit_and_mantle_blockchain_models.py new file mode 100644 index 0000000..9d71c6a --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/9ca39b11e12a_game7_orbit_and_mantle_blockchain_models.py @@ -0,0 +1,157 @@ +"""Game7 Orbit and Mantle blockchain models + +Revision ID: 9ca39b11e12a +Revises: d2ceff33be47 +Create Date: 2024-05-29 13:17:07.194421 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = '9ca39b11e12a' +down_revision: Union[str, None] = 'd2ceff33be47' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('game7_orbit_arbitrum_sepolia_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_game7_orbit_arbitrum_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_game7_orbit_arbitrum_sepolia_labels_id')) + ) + op.create_index('ix_g7o_arbitrum_sepolia_labels_addr_block_num', 'game7_orbit_arbitrum_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_g7o_arbitrum_sepolia_labels_addr_block_ts', 'game7_orbit_arbitrum_sepolia_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_address'), 'game7_orbit_arbitrum_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_block_number'), 'game7_orbit_arbitrum_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_caller_address'), 'game7_orbit_arbitrum_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_label'), 'game7_orbit_arbitrum_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_label_name'), 'game7_orbit_arbitrum_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_label_type'), 'game7_orbit_arbitrum_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_origin_address'), 'game7_orbit_arbitrum_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_transaction_hash'), 'game7_orbit_arbitrum_sepolia_labels', ['transaction_hash'], unique=False) + op.create_index('uk_g7o_arbitrum_sepolia_labels_tx_hash_log_idx_evt', 'game7_orbit_arbitrum_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_g7o_arbitrum_sepolia_labels_tx_hash_tx_call', 'game7_orbit_arbitrum_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.create_table('mantle_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_mantle_labels')), + sa.UniqueConstraint('id', name=op.f('uq_mantle_labels_id')) + ) + op.create_index('ix_mantle_labels_addr_block_num', 'mantle_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_mantle_labels_addr_block_ts', 'mantle_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_mantle_labels_address'), 'mantle_labels', ['address'], unique=False) + op.create_index(op.f('ix_mantle_labels_block_number'), 'mantle_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_mantle_labels_caller_address'), 'mantle_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_mantle_labels_label'), 'mantle_labels', ['label'], unique=False) + op.create_index(op.f('ix_mantle_labels_label_name'), 'mantle_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_mantle_labels_label_type'), 'mantle_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_mantle_labels_origin_address'), 'mantle_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_mantle_labels_transaction_hash'), 'mantle_labels', ['transaction_hash'], unique=False) + op.create_index('uk_mantle_labels_tx_hash_log_idx_evt', 'mantle_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_mantle_labels_tx_hash_tx_call', 'mantle_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.create_table('mantle_sepolia_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_mantle_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_mantle_sepolia_labels_id')) + ) + op.create_index('ix_mantle_sepolia_labels_addr_block_num', 'mantle_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_mantle_sepolia_labels_addr_block_ts', 'mantle_sepolia_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_labels_address'), 'mantle_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_labels_block_number'), 'mantle_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_labels_caller_address'), 'mantle_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_labels_label'), 'mantle_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_labels_label_name'), 'mantle_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_labels_label_type'), 'mantle_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_labels_origin_address'), 'mantle_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_labels_transaction_hash'), 'mantle_sepolia_labels', ['transaction_hash'], unique=False) + op.create_index('uk_mantle_sepolia_labels_tx_hash_log_idx_evt', 'mantle_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_mantle_sepolia_labels_tx_hash_tx_call', 'mantle_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index('uk_mantle_sepolia_labels_tx_hash_tx_call', table_name='mantle_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_mantle_sepolia_labels_tx_hash_log_idx_evt', table_name='mantle_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index(op.f('ix_mantle_sepolia_labels_transaction_hash'), table_name='mantle_sepolia_labels') + op.drop_index(op.f('ix_mantle_sepolia_labels_origin_address'), table_name='mantle_sepolia_labels') + op.drop_index(op.f('ix_mantle_sepolia_labels_label_type'), table_name='mantle_sepolia_labels') + op.drop_index(op.f('ix_mantle_sepolia_labels_label_name'), table_name='mantle_sepolia_labels') + op.drop_index(op.f('ix_mantle_sepolia_labels_label'), table_name='mantle_sepolia_labels') + op.drop_index(op.f('ix_mantle_sepolia_labels_caller_address'), table_name='mantle_sepolia_labels') + op.drop_index(op.f('ix_mantle_sepolia_labels_block_number'), table_name='mantle_sepolia_labels') + op.drop_index(op.f('ix_mantle_sepolia_labels_address'), table_name='mantle_sepolia_labels') + op.drop_index('ix_mantle_sepolia_labels_addr_block_ts', table_name='mantle_sepolia_labels') + op.drop_index('ix_mantle_sepolia_labels_addr_block_num', table_name='mantle_sepolia_labels') + op.drop_table('mantle_sepolia_labels') + op.drop_index('uk_mantle_labels_tx_hash_tx_call', table_name='mantle_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_mantle_labels_tx_hash_log_idx_evt', table_name='mantle_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index(op.f('ix_mantle_labels_transaction_hash'), table_name='mantle_labels') + op.drop_index(op.f('ix_mantle_labels_origin_address'), table_name='mantle_labels') + op.drop_index(op.f('ix_mantle_labels_label_type'), table_name='mantle_labels') + op.drop_index(op.f('ix_mantle_labels_label_name'), table_name='mantle_labels') + op.drop_index(op.f('ix_mantle_labels_label'), table_name='mantle_labels') + op.drop_index(op.f('ix_mantle_labels_caller_address'), table_name='mantle_labels') + op.drop_index(op.f('ix_mantle_labels_block_number'), table_name='mantle_labels') + op.drop_index(op.f('ix_mantle_labels_address'), table_name='mantle_labels') + op.drop_index('ix_mantle_labels_addr_block_ts', table_name='mantle_labels') + op.drop_index('ix_mantle_labels_addr_block_num', table_name='mantle_labels') + op.drop_table('mantle_labels') + op.drop_index('uk_g7o_arbitrum_sepolia_labels_tx_hash_tx_call', table_name='game7_orbit_arbitrum_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_g7o_arbitrum_sepolia_labels_tx_hash_log_idx_evt', table_name='game7_orbit_arbitrum_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_transaction_hash'), table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_origin_address'), table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_label_type'), table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_label_name'), table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_label'), table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_caller_address'), table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_block_number'), table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_labels_address'), table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_index('ix_g7o_arbitrum_sepolia_labels_addr_block_ts', table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_index('ix_g7o_arbitrum_sepolia_labels_addr_block_num', table_name='game7_orbit_arbitrum_sepolia_labels') + op.drop_table('game7_orbit_arbitrum_sepolia_labels') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/__init__.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/d2ceff33be47_tx_call_and_event_unique_indexes.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/d2ceff33be47_tx_call_and_event_unique_indexes.py new file mode 100644 index 0000000..b2f2a3b --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/d2ceff33be47_tx_call_and_event_unique_indexes.py @@ -0,0 +1,133 @@ +"""tx call and event unique indexes + +Revision ID: d2ceff33be47 +Revises: e9f640a2b45b +Create Date: 2024-05-17 16:35:56.059519 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'd2ceff33be47' +down_revision: Union[str, None] = 'e9f640a2b45b' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + # uq_amoy_labels + op.create_index('uk_amoy_labels_tx_hash_log_idx_evt', 'amoy_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_amoy_labels_tx_hash_tx_call', 'amoy_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_arbitrum_nova_labels + op.create_index('uk_arbitrum_nova_labels_tx_hash_log_idx_evt', 'arbitrum_nova_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_arbitrum_nova_labels_tx_hash_tx_call', 'arbitrum_nova_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_arbitrum_one_labels + op.create_index('uk_arbitrum_one_labels_tx_hash_log_idx_evt', 'arbitrum_one_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_arbitrum_one_labels_tx_hash_tx_call', 'arbitrum_one_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_arbitrum_sepolia_labels + op.create_index('uk_arbitrum_sepolia_labels_tx_hash_log_idx_evt', 'arbitrum_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_arbitrum_sepolia_labels_tx_hash_tx_call', 'arbitrum_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_avalanche_fuji_labels + op.create_index('uk_avalanche_fuji_labels_tx_hash_log_idx_evt', 'avalanche_fuji_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_avalanche_fuji_labels_tx_hash_tx_call', 'avalanche_fuji_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_avalanche_labels + op.create_index('uk_avalanche_labels_tx_hash_log_idx_evt', 'avalanche_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_avalanche_labels_tx_hash_tx_call', 'avalanche_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_base_labels + op.create_index('uk_base_labels_tx_hash_log_idx_evt', 'base_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_base_labels_tx_hash_tx_call', 'base_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_blast_labels + op.create_index('uk_blast_labels_tx_hash_log_idx_evt', 'blast_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_blast_labels_tx_hash_tx_call', 'blast_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_blast_sepolia_labels + op.create_index('uk_blast_sepolia_labels_tx_hash_log_idx_evt', 'blast_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_blast_sepolia_labels_tx_hash_tx_call', 'blast_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_ethereum_labels + op.create_index('uk_ethereum_labels_tx_hash_log_idx_evt', 'ethereum_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_ethereum_labels_tx_hash_tx_call', 'ethereum_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_mumbai_labels + op.create_index('uk_mumbai_labels_tx_hash_log_idx_evt', 'mumbai_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_mumbai_labels_tx_hash_tx_call', 'mumbai_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_polygon_labels + op.create_index('uk_polygon_labels_tx_hash_log_idx_evt', 'polygon_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_polygon_labels_tx_hash_tx_call', 'polygon_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_proofofplay_apex_labels + op.create_index('uk_proofofplay_apex_labels_tx_hash_log_idx_evt', 'proofofplay_apex_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_proofofplay_apex_labels_tx_hash_tx_call', 'proofofplay_apex_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_sepolia_labels + op.create_index('uk_sepolia_labels_tx_hash_log_idx_evt', 'sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_sepolia_labels_tx_hash_tx_call', 'sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_starknet_labels + op.create_index('uk_starknet_labels_tx_hash_log_idx_evt', 'starknet_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_starknet_labels_tx_hash_tx_call', 'starknet_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_starknet_sepolia_labels + op.create_index('uk_starknet_sepolia_labels_tx_hash_log_idx_evt', 'starknet_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_starknet_sepolia_labels_tx_hash_tx_call', 'starknet_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_xai_labels + op.create_index('uk_xai_labels_tx_hash_log_idx_evt', 'xai_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_xai_labels_tx_hash_tx_call', 'xai_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # uq_xai_sepolia_labels + op.create_index('uk_xai_sepolia_labels_tx_hash_log_idx_evt', 'xai_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_xai_sepolia_labels_tx_hash_tx_call', 'xai_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # xdai_labels + op.create_index('uk_xdai_labels_tx_hash_log_idx_evt', 'xdai_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_xdai_labels_tx_hash_tx_call', 'xdai_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # zksync_era_labels + op.create_index('uk_zksync_era_labels_tx_hash_log_idx_evt', 'zksync_era_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_zksync_era_labels_tx_hash_tx_call', 'zksync_era_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # zksync_era_sepolia_labels + op.create_index('uk_zksync_era_sepolia_labels_tx_hash_log_idx_evt', 'zksync_era_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_zksync_era_sepolia_labels_tx_hash_tx_call', 'zksync_era_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index('uk_zksync_era_sepolia_labels_tx_hash_tx_call', table_name='zksync_era_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_zksync_era_sepolia_labels_tx_hash_log_idx_evt', table_name='zksync_era_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_zksync_era_labels_tx_hash_tx_call', table_name='zksync_era_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_zksync_era_labels_tx_hash_log_idx_evt', table_name='zksync_era_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_xdai_labels_tx_hash_tx_call', table_name='xdai_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_xdai_labels_tx_hash_log_idx_evt', table_name='xdai_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_xai_sepolia_labels_tx_hash_tx_call', table_name='xai_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_xai_sepolia_labels_tx_hash_log_idx_evt', table_name='xai_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_xai_labels_tx_hash_tx_call', table_name='xai_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_xai_labels_tx_hash_log_idx_evt', table_name='xai_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_starknet_sepolia_labels_tx_hash_tx_call', table_name='starknet_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_starknet_sepolia_labels_tx_hash_log_idx_evt', table_name='starknet_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_starknet_labels_tx_hash_tx_call', table_name='starknet_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_starknet_labels_tx_hash_log_idx_evt', table_name='starknet_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_sepolia_labels_tx_hash_tx_call', table_name='sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_sepolia_labels_tx_hash_log_idx_evt', table_name='sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_proofofplay_apex_labels_tx_hash_tx_call', table_name='proofofplay_apex_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_proofofplay_apex_labels_tx_hash_log_idx_evt', table_name='proofofplay_apex_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_polygon_labels_tx_hash_tx_call', table_name='polygon_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_polygon_labels_tx_hash_log_idx_evt', table_name='polygon_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_mumbai_labels_tx_hash_tx_call', table_name='mumbai_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_mumbai_labels_tx_hash_log_idx_evt', table_name='mumbai_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_ethereum_labels_tx_hash_tx_call', table_name='ethereum_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_ethereum_labels_tx_hash_log_idx_evt', table_name='ethereum_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_blast_sepolia_labels_tx_hash_tx_call', table_name='blast_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_blast_sepolia_labels_tx_hash_log_idx_evt', table_name='blast_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_blast_labels_tx_hash_tx_call', table_name='blast_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_blast_labels_tx_hash_log_idx_evt', table_name='blast_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_base_labels_tx_hash_tx_call', table_name='base_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_base_labels_tx_hash_log_idx_evt', table_name='base_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_avalanche_labels_tx_hash_tx_call', table_name='avalanche_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_avalanche_labels_tx_hash_log_idx_evt', table_name='avalanche_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_avalanche_fuji_labels_tx_hash_tx_call', table_name='avalanche_fuji_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_avalanche_fuji_labels_tx_hash_log_idx_evt', table_name='avalanche_fuji_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_arbitrum_sepolia_labels_tx_hash_tx_call', table_name='arbitrum_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_arbitrum_sepolia_labels_tx_hash_log_idx_evt', table_name='arbitrum_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_arbitrum_one_labels_tx_hash_tx_call', table_name='arbitrum_one_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_arbitrum_one_labels_tx_hash_log_idx_evt', table_name='arbitrum_one_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_arbitrum_nova_labels_tx_hash_tx_call', table_name='arbitrum_nova_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_arbitrum_nova_labels_tx_hash_log_idx_evt', table_name='arbitrum_nova_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index('uk_amoy_labels_tx_hash_tx_call', table_name='amoy_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_amoy_labels_tx_hash_log_idx_evt', table_name='amoy_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/d816689b786a_add_game7_mainnet_labels.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/d816689b786a_add_game7_mainnet_labels.py new file mode 100644 index 0000000..3ff01ba --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/d816689b786a_add_game7_mainnet_labels.py @@ -0,0 +1,75 @@ +"""Add Game7 mainnet labels + +Revision ID: d816689b786a +Revises: 1d53afc1eff4 +Create Date: 2024-10-14 15:58:21.374247 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = 'd816689b786a' +down_revision: Union[str, None] = '1d53afc1eff4' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('game7_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.LargeBinary(), nullable=True), + sa.Column('origin_address', sa.LargeBinary(), nullable=True), + sa.Column('address', sa.LargeBinary(), nullable=False), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_game7_labels')), + sa.UniqueConstraint('id', name=op.f('uq_game7_labels_id')) + ) + op.create_index('ix_game7_labels_addr_block_num', 'game7_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_game7_labels_addr_block_ts', 'game7_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_game7_labels_address'), 'game7_labels', ['address'], unique=False) + op.create_index(op.f('ix_game7_labels_block_number'), 'game7_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_game7_labels_caller_address'), 'game7_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_game7_labels_label'), 'game7_labels', ['label'], unique=False) + op.create_index(op.f('ix_game7_labels_label_name'), 'game7_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_game7_labels_label_type'), 'game7_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_game7_labels_origin_address'), 'game7_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_game7_labels_transaction_hash'), 'game7_labels', ['transaction_hash'], unique=False) + op.create_index('uk_game7_labels_tx_hash_log_idx_evt', 'game7_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_game7_labels_tx_hash_log_idx_evt_raw', 'game7_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.create_index('uk_game7_labels_tx_hash_tx_call', 'game7_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.create_index('uk_game7_labels_tx_hash_tx_call_raw', 'game7_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'")) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index('uk_game7_labels_tx_hash_tx_call_raw', table_name='game7_labels', postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'")) + op.drop_index('uk_game7_labels_tx_hash_tx_call', table_name='game7_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_game7_labels_tx_hash_log_idx_evt_raw', table_name='game7_labels', postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.drop_index('uk_game7_labels_tx_hash_log_idx_evt', table_name='game7_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index(op.f('ix_game7_labels_transaction_hash'), table_name='game7_labels') + op.drop_index(op.f('ix_game7_labels_origin_address'), table_name='game7_labels') + op.drop_index(op.f('ix_game7_labels_label_type'), table_name='game7_labels') + op.drop_index(op.f('ix_game7_labels_label_name'), table_name='game7_labels') + op.drop_index(op.f('ix_game7_labels_label'), table_name='game7_labels') + op.drop_index(op.f('ix_game7_labels_caller_address'), table_name='game7_labels') + op.drop_index(op.f('ix_game7_labels_block_number'), table_name='game7_labels') + op.drop_index(op.f('ix_game7_labels_address'), table_name='game7_labels') + op.drop_index('ix_game7_labels_addr_block_ts', table_name='game7_labels') + op.drop_index('ix_game7_labels_addr_block_num', table_name='game7_labels') + op.drop_table('game7_labels') + # ### end Alembic commands ### \ No newline at end of file diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/db9559f9566c_add_game7_testnet.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/db9559f9566c_add_game7_testnet.py new file mode 100644 index 0000000..4e17506 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/db9559f9566c_add_game7_testnet.py @@ -0,0 +1,195 @@ +"""Add game7 testnet + +Revision ID: db9559f9566c +Revises: 211646463e9f +Create Date: 2024-08-05 16:24:26.159323 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = "db9559f9566c" +down_revision: Union[str, None] = "211646463e9f" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "game7_testnet_labels", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("label", sa.VARCHAR(length=256), nullable=False), + sa.Column("transaction_hash", sa.VARCHAR(length=128), nullable=False), + sa.Column("log_index", sa.Integer(), nullable=True), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("caller_address", sa.LargeBinary(), nullable=True), + sa.Column("origin_address", sa.LargeBinary(), nullable=True), + sa.Column("address", sa.LargeBinary(), nullable=False), + sa.Column("label_name", sa.Text(), nullable=True), + sa.Column("label_type", sa.VARCHAR(length=64), nullable=True), + sa.Column("label_data", postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column( + "created_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("id", name=op.f("pk_game7_testnet_labels")), + sa.UniqueConstraint("id", name=op.f("uq_game7_testnet_labels_id")), + ) + op.create_index( + "ix_game7_testnet_labels_addr_block_num", + "game7_testnet_labels", + ["address", "block_number"], + unique=False, + ) + op.create_index( + "ix_game7_testnet_labels_addr_block_ts", + "game7_testnet_labels", + ["address", "block_timestamp"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_labels_address"), + "game7_testnet_labels", + ["address"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_labels_block_number"), + "game7_testnet_labels", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_labels_caller_address"), + "game7_testnet_labels", + ["caller_address"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_labels_label"), + "game7_testnet_labels", + ["label"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_labels_label_name"), + "game7_testnet_labels", + ["label_name"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_labels_label_type"), + "game7_testnet_labels", + ["label_type"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_labels_origin_address"), + "game7_testnet_labels", + ["origin_address"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_labels_transaction_hash"), + "game7_testnet_labels", + ["transaction_hash"], + unique=False, + ) + op.create_index( + "uk_game7_testnet_labels_tx_hash_log_idx_evt", + "game7_testnet_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.create_index( + "uk_game7_testnet_labels_tx_hash_log_idx_evt_raw", + "game7_testnet_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_game7_testnet_labels_tx_hash_tx_call", + "game7_testnet_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.create_index( + "uk_game7_testnet_labels_tx_hash_tx_call_raw", + "game7_testnet_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + "uk_game7_testnet_labels_tx_hash_tx_call_raw", + table_name="game7_testnet_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_game7_testnet_labels_tx_hash_tx_call", + table_name="game7_testnet_labels", + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.drop_index( + "uk_game7_testnet_labels_tx_hash_log_idx_evt_raw", + table_name="game7_testnet_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_game7_testnet_labels_tx_hash_log_idx_evt", + table_name="game7_testnet_labels", + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.drop_index( + op.f("ix_game7_testnet_labels_transaction_hash"), + table_name="game7_testnet_labels", + ) + op.drop_index( + op.f("ix_game7_testnet_labels_origin_address"), + table_name="game7_testnet_labels", + ) + op.drop_index( + op.f("ix_game7_testnet_labels_label_type"), table_name="game7_testnet_labels" + ) + op.drop_index( + op.f("ix_game7_testnet_labels_label_name"), table_name="game7_testnet_labels" + ) + op.drop_index( + op.f("ix_game7_testnet_labels_label"), table_name="game7_testnet_labels" + ) + op.drop_index( + op.f("ix_game7_testnet_labels_caller_address"), + table_name="game7_testnet_labels", + ) + op.drop_index( + op.f("ix_game7_testnet_labels_block_number"), table_name="game7_testnet_labels" + ) + op.drop_index( + op.f("ix_game7_testnet_labels_address"), table_name="game7_testnet_labels" + ) + op.drop_index( + "ix_game7_testnet_labels_addr_block_ts", table_name="game7_testnet_labels" + ) + op.drop_index( + "ix_game7_testnet_labels_addr_block_num", table_name="game7_testnet_labels" + ) + op.drop_table("game7_testnet_labels") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/e9e1b43f49e1_amoy_blast_and_apex_blockchains.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/e9e1b43f49e1_amoy_blast_and_apex_blockchains.py new file mode 100644 index 0000000..4bea7e5 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/e9e1b43f49e1_amoy_blast_and_apex_blockchains.py @@ -0,0 +1,185 @@ +"""Amoy, Blast and Apex blockchains + +Revision ID: e9e1b43f49e1 +Revises: 994e614b5500 +Create Date: 2024-04-22 09:35:56.509834 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = 'e9e1b43f49e1' +down_revision: Union[str, None] = '994e614b5500' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('amoy_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_amoy_labels')), + sa.UniqueConstraint('id', name=op.f('uq_amoy_labels_id')) + ) + op.create_index('ix_amoy_labels_addr_block_num', 'amoy_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_amoy_labels_addr_block_ts', 'amoy_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_amoy_labels_address'), 'amoy_labels', ['address'], unique=False) + op.create_index(op.f('ix_amoy_labels_block_number'), 'amoy_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_amoy_labels_caller_address'), 'amoy_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_amoy_labels_label'), 'amoy_labels', ['label'], unique=False) + op.create_index(op.f('ix_amoy_labels_label_name'), 'amoy_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_amoy_labels_label_type'), 'amoy_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_amoy_labels_origin_address'), 'amoy_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_amoy_labels_transaction_hash'), 'amoy_labels', ['transaction_hash'], unique=False) + op.create_table('blast_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_blast_labels')), + sa.UniqueConstraint('id', name=op.f('uq_blast_labels_id')) + ) + op.create_index('ix_blast_labels_addr_block_num', 'blast_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_blast_labels_addr_block_ts', 'blast_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_blast_labels_address'), 'blast_labels', ['address'], unique=False) + op.create_index(op.f('ix_blast_labels_block_number'), 'blast_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_blast_labels_caller_address'), 'blast_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_blast_labels_label'), 'blast_labels', ['label'], unique=False) + op.create_index(op.f('ix_blast_labels_label_name'), 'blast_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_blast_labels_label_type'), 'blast_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_blast_labels_origin_address'), 'blast_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_blast_labels_transaction_hash'), 'blast_labels', ['transaction_hash'], unique=False) + op.create_table('blast_sepolia_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_blast_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_blast_sepolia_labels_id')) + ) + op.create_index('ix_blast_sepolia_labels_addr_block_num', 'blast_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_blast_sepolia_labels_addr_block_ts', 'blast_sepolia_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_address'), 'blast_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_block_number'), 'blast_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_caller_address'), 'blast_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_label'), 'blast_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_label_name'), 'blast_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_label_type'), 'blast_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_origin_address'), 'blast_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_transaction_hash'), 'blast_sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('proofofplay_apex_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_proofofplay_apex_labels')), + sa.UniqueConstraint('id', name=op.f('uq_proofofplay_apex_labels_id')) + ) + op.create_index('ix_proofofplay_apex_labels_addr_block_num', 'proofofplay_apex_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_proofofplay_apex_labels_addr_block_ts', 'proofofplay_apex_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_proofofplay_apex_labels_address'), 'proofofplay_apex_labels', ['address'], unique=False) + op.create_index(op.f('ix_proofofplay_apex_labels_block_number'), 'proofofplay_apex_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_proofofplay_apex_labels_caller_address'), 'proofofplay_apex_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_proofofplay_apex_labels_label'), 'proofofplay_apex_labels', ['label'], unique=False) + op.create_index(op.f('ix_proofofplay_apex_labels_label_name'), 'proofofplay_apex_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_proofofplay_apex_labels_label_type'), 'proofofplay_apex_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_proofofplay_apex_labels_origin_address'), 'proofofplay_apex_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_proofofplay_apex_labels_transaction_hash'), 'proofofplay_apex_labels', ['transaction_hash'], unique=False) + op.create_index('ix_arbitrum_nova_labels_addr_block_ts', 'arbitrum_nova_labels', ['address', 'block_timestamp'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_proofofplay_apex_labels_transaction_hash'), table_name='proofofplay_apex_labels') + op.drop_index(op.f('ix_proofofplay_apex_labels_origin_address'), table_name='proofofplay_apex_labels') + op.drop_index(op.f('ix_proofofplay_apex_labels_label_type'), table_name='proofofplay_apex_labels') + op.drop_index(op.f('ix_proofofplay_apex_labels_label_name'), table_name='proofofplay_apex_labels') + op.drop_index(op.f('ix_proofofplay_apex_labels_label'), table_name='proofofplay_apex_labels') + op.drop_index(op.f('ix_proofofplay_apex_labels_caller_address'), table_name='proofofplay_apex_labels') + op.drop_index(op.f('ix_proofofplay_apex_labels_block_number'), table_name='proofofplay_apex_labels') + op.drop_index(op.f('ix_proofofplay_apex_labels_address'), table_name='proofofplay_apex_labels') + op.drop_index('ix_proofofplay_apex_labels_addr_block_ts', table_name='proofofplay_apex_labels') + op.drop_index('ix_proofofplay_apex_labels_addr_block_num', table_name='proofofplay_apex_labels') + op.drop_table('proofofplay_apex_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_transaction_hash'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_origin_address'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_label_type'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_label_name'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_label'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_caller_address'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_block_number'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_address'), table_name='blast_sepolia_labels') + op.drop_index('ix_blast_sepolia_labels_addr_block_ts', table_name='blast_sepolia_labels') + op.drop_index('ix_blast_sepolia_labels_addr_block_num', table_name='blast_sepolia_labels') + op.drop_table('blast_sepolia_labels') + op.drop_index(op.f('ix_blast_labels_transaction_hash'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_origin_address'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_label_type'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_label_name'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_label'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_caller_address'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_block_number'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_address'), table_name='blast_labels') + op.drop_index('ix_blast_labels_addr_block_ts', table_name='blast_labels') + op.drop_index('ix_blast_labels_addr_block_num', table_name='blast_labels') + op.drop_table('blast_labels') + op.drop_index(op.f('ix_amoy_labels_transaction_hash'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_origin_address'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_label_type'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_label_name'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_label'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_caller_address'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_block_number'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_address'), table_name='amoy_labels') + op.drop_index('ix_amoy_labels_addr_block_ts', table_name='amoy_labels') + op.drop_index('ix_amoy_labels_addr_block_num', table_name='amoy_labels') + op.drop_table('amoy_labels') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/e9f640a2b45b_arbitrum_one_blockchain.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/e9f640a2b45b_arbitrum_one_blockchain.py new file mode 100644 index 0000000..a72c12d --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/e9f640a2b45b_arbitrum_one_blockchain.py @@ -0,0 +1,67 @@ +"""Arbitrum One blockchain + +Revision ID: e9f640a2b45b +Revises: e9e1b43f49e1 +Create Date: 2024-05-10 10:39:21.257483 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = 'e9f640a2b45b' +down_revision: Union[str, None] = 'e9e1b43f49e1' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('arbitrum_one_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False), + sa.Column('log_index', sa.Integer(), nullable=True), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('caller_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_name', sa.Text(), nullable=True), + sa.Column('label_type', sa.VARCHAR(length=64), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_arbitrum_one_labels')), + sa.UniqueConstraint('id', name=op.f('uq_arbitrum_one_labels_id')) + ) + op.create_index('ix_arbitrum_one_labels_addr_block_num', 'arbitrum_one_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_arbitrum_one_labels_addr_block_ts', 'arbitrum_one_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_arbitrum_one_labels_address'), 'arbitrum_one_labels', ['address'], unique=False) + op.create_index(op.f('ix_arbitrum_one_labels_block_number'), 'arbitrum_one_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_one_labels_caller_address'), 'arbitrum_one_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_arbitrum_one_labels_label'), 'arbitrum_one_labels', ['label'], unique=False) + op.create_index(op.f('ix_arbitrum_one_labels_label_name'), 'arbitrum_one_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_arbitrum_one_labels_label_type'), 'arbitrum_one_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_arbitrum_one_labels_origin_address'), 'arbitrum_one_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_arbitrum_one_labels_transaction_hash'), 'arbitrum_one_labels', ['transaction_hash'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_arbitrum_one_labels_transaction_hash'), table_name='arbitrum_one_labels') + op.drop_index(op.f('ix_arbitrum_one_labels_origin_address'), table_name='arbitrum_one_labels') + op.drop_index(op.f('ix_arbitrum_one_labels_label_type'), table_name='arbitrum_one_labels') + op.drop_index(op.f('ix_arbitrum_one_labels_label_name'), table_name='arbitrum_one_labels') + op.drop_index(op.f('ix_arbitrum_one_labels_label'), table_name='arbitrum_one_labels') + op.drop_index(op.f('ix_arbitrum_one_labels_caller_address'), table_name='arbitrum_one_labels') + op.drop_index(op.f('ix_arbitrum_one_labels_block_number'), table_name='arbitrum_one_labels') + op.drop_index(op.f('ix_arbitrum_one_labels_address'), table_name='arbitrum_one_labels') + op.drop_index('ix_arbitrum_one_labels_addr_block_ts', table_name='arbitrum_one_labels') + op.drop_index('ix_arbitrum_one_labels_addr_block_num', table_name='arbitrum_one_labels') + op.drop_table('arbitrum_one_labels') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/README b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/README new file mode 100644 index 0000000..98e4f9c --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/README @@ -0,0 +1 @@ +Generic single-database configuration. \ No newline at end of file diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/__init__.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py new file mode 100644 index 0000000..6552c0b --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py @@ -0,0 +1,105 @@ +from logging.config import fileConfig +from alembic import context +from sqlalchemy import engine_from_config, pool +import os +import sys +import pkgutil +import importlib +from sqlalchemy.ext.declarative import DeclarativeMeta + +# Get the Alembic Config object +config = context.config + +# Interpret the config file for Python logging +if config.config_file_name is not None: + fileConfig(config.config_file_name) + +# Add project directory to sys.path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + +# Import Base and target metadata +from models_indexes.abstract_indexes import Base as IndexesBase + +target_metadata = IndexesBase.metadata + + +# Dynamically import all models +def import_models(package_name): + package = importlib.import_module(package_name) + ###print(dir(package)) + for loader, module_name, is_pkg in pkgutil.walk_packages( + package.__path__, package_name + "." + ): + if module_name == "__init__": + continue + importlib.import_module(module_name) + + +import_models("moonstreamdbv3.models_indexes") + + +# Collect all model classes +def get_model_classes(base): + return base.__subclasses__() + [ + cls for scls in base.__subclasses__() for cls in get_model_classes(scls) + ] + + +model_classes = get_model_classes(IndexesBase) + +# Generate set of table names +model_tablenames = { + cls.__tablename__ for cls in model_classes if hasattr(cls, "__tablename__") +} + +print(model_tablenames) + + +# Define include_symbol function +def include_symbol(tablename, schema): + return tablename in model_tablenames + + +# Run migrations offline +def run_migrations_offline(): + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, + target_metadata=target_metadata, + include_symbol=include_symbol, + literal_binds=True, + dialect_opts={"paramstyle": "named"}, + version_table="alembic_version", + include_schemas=True, + ) + + with context.begin_transaction(): + context.run_migrations() + + +# Run migrations online +def run_migrations_online(): + connectable = engine_from_config( + config.get_section(config.config_ini_section, {}), + prefix="sqlalchemy.", + poolclass=pool.NullPool, + ) + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata, + include_symbol=include_symbol, + version_table="alembic_version", + include_schemas=True, + ) + + with context.begin_transaction(): + context.run_migrations() + + +# Determine if running offline or online +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/script.py.mako b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/script.py.mako new file mode 100644 index 0000000..fbc4b07 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/script.py.mako @@ -0,0 +1,26 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision: str = ${repr(up_revision)} +down_revision: Union[str, None] = ${repr(down_revision)} +branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)} +depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)} + + +def upgrade() -> None: + ${upgrades if upgrades else "pass"} + + +def downgrade() -> None: + ${downgrades if downgrades else "pass"} diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/0ea24314c181_init_v3_index.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/0ea24314c181_init_v3_index.py new file mode 100644 index 0000000..07731d4 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/0ea24314c181_init_v3_index.py @@ -0,0 +1,225 @@ +"""init v3 index + +Revision ID: 0ea24314c181 +Revises: +Create Date: 2024-05-23 17:39:53.824404 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = '0ea24314c181' +down_revision: Union[str, None] = None +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('abi_jobs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('address', sa.LargeBinary(), nullable=False), + sa.Column('user_id', sa.UUID(), nullable=False), + sa.Column('customer_id', sa.UUID(), nullable=True), + sa.Column('abi_selector', sa.VARCHAR(length=256), nullable=False), + sa.Column('chain', sa.VARCHAR(length=256), nullable=False), + sa.Column('abi_name', sa.VARCHAR(length=256), nullable=False), + sa.Column('status', sa.VARCHAR(length=256), nullable=False), + sa.Column('historical_crawl_status', sa.VARCHAR(length=256), nullable=False), + sa.Column('progress', sa.Integer(), nullable=False), + sa.Column('moonworm_task_pickedup', sa.Boolean(), nullable=False), + sa.Column('abi', sa.Text(), nullable=False), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_abi_jobs')), + sa.UniqueConstraint('chain', 'address', 'abi_selector', 'customer_id', name='uq_abi_jobs') + ) + op.create_index(op.f('ix_abi_jobs_abi_name'), 'abi_jobs', ['abi_name'], unique=False) + op.create_index(op.f('ix_abi_jobs_abi_selector'), 'abi_jobs', ['abi_selector'], unique=False) + op.create_index(op.f('ix_abi_jobs_address'), 'abi_jobs', ['address'], unique=False) + op.create_index(op.f('ix_abi_jobs_chain'), 'abi_jobs', ['chain'], unique=False) + op.create_index(op.f('ix_abi_jobs_customer_id'), 'abi_jobs', ['customer_id'], unique=False) + op.create_index(op.f('ix_abi_jobs_historical_crawl_status'), 'abi_jobs', ['historical_crawl_status'], unique=False) + op.create_index(op.f('ix_abi_jobs_status'), 'abi_jobs', ['status'], unique=False) + op.create_index(op.f('ix_abi_jobs_user_id'), 'abi_jobs', ['user_id'], unique=False) + op.create_table('ethereum_blocks', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_ethereum_blocks')) + ) + op.create_index(op.f('ix_ethereum_blocks_block_number'), 'ethereum_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_ethereum_blocks_block_timestamp'), 'ethereum_blocks', ['block_timestamp'], unique=False) + op.create_table('ethereum_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_ethereum_reorgs')) + ) + op.create_index(op.f('ix_ethereum_reorgs_block_hash'), 'ethereum_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_ethereum_reorgs_block_number'), 'ethereum_reorgs', ['block_number'], unique=False) + op.create_table('polygon_blocks', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_polygon_blocks')) + ) + op.create_index(op.f('ix_polygon_blocks_block_number'), 'polygon_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_polygon_blocks_block_timestamp'), 'polygon_blocks', ['block_timestamp'], unique=False) + op.create_table('polygon_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_polygon_reorgs')) + ) + op.create_index(op.f('ix_polygon_reorgs_block_hash'), 'polygon_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_polygon_reorgs_block_number'), 'polygon_reorgs', ['block_number'], unique=False) + op.create_table('ethereum_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['ethereum_blocks.block_number'], name=op.f('fk_ethereum_transactions_block_number_ethereum_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_ethereum_transactions')) + ) + op.create_index(op.f('ix_ethereum_transactions_block_hash'), 'ethereum_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_ethereum_transactions_block_number'), 'ethereum_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_ethereum_transactions_from_address'), 'ethereum_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_ethereum_transactions_hash'), 'ethereum_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_ethereum_transactions_index'), 'ethereum_transactions', ['index'], unique=False) + op.create_index(op.f('ix_ethereum_transactions_selector'), 'ethereum_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_ethereum_transactions_to_address'), 'ethereum_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_ethereum_transactions_type'), 'ethereum_transactions', ['type'], unique=False) + op.create_table('polygon_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['polygon_blocks.block_number'], name=op.f('fk_polygon_transactions_block_number_polygon_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_polygon_transactions')) + ) + op.create_index(op.f('ix_polygon_transactions_block_hash'), 'polygon_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_polygon_transactions_block_number'), 'polygon_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_polygon_transactions_from_address'), 'polygon_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_polygon_transactions_hash'), 'polygon_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_polygon_transactions_index'), 'polygon_transactions', ['index'], unique=False) + op.create_index(op.f('ix_polygon_transactions_selector'), 'polygon_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_polygon_transactions_to_address'), 'polygon_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_polygon_transactions_type'), 'polygon_transactions', ['type'], unique=False) + op.create_table('ethereum_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['ethereum_transactions.hash'], name=op.f('fk_ethereum_logs_transaction_hash_ethereum_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_ethereum_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_ethereum_log_index_transaction_hash_log_index') + ) + op.create_index('idx_ethereum_logs_block_hash_log_index', 'ethereum_logs', ['block_hash', 'log_index'], unique=True) + op.create_index(op.f('ix_ethereum_logs_address'), 'ethereum_logs', ['address'], unique=False) + op.create_index(op.f('ix_ethereum_logs_block_hash'), 'ethereum_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_ethereum_logs_transaction_hash'), 'ethereum_logs', ['transaction_hash'], unique=False) + op.create_table('polygon_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['polygon_transactions.hash'], name=op.f('fk_polygon_logs_transaction_hash_polygon_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_polygon_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_polygon_log_index_transaction_hash_log_index') + ) + op.create_index(op.f('ix_polygon_logs_address'), 'polygon_logs', ['address'], unique=False) + op.create_index(op.f('ix_polygon_logs_block_hash'), 'polygon_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_polygon_logs_transaction_hash'), 'polygon_logs', ['transaction_hash'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_polygon_logs_transaction_hash'), table_name='polygon_logs') + op.drop_index(op.f('ix_polygon_logs_block_hash'), table_name='polygon_logs') + op.drop_index(op.f('ix_polygon_logs_address'), table_name='polygon_logs') + op.drop_table('polygon_logs') + op.drop_index(op.f('ix_ethereum_logs_transaction_hash'), table_name='ethereum_logs') + op.drop_index(op.f('ix_ethereum_logs_block_hash'), table_name='ethereum_logs') + op.drop_index(op.f('ix_ethereum_logs_address'), table_name='ethereum_logs') + op.drop_index('idx_ethereum_logs_block_hash_log_index', table_name='ethereum_logs') + op.drop_table('ethereum_logs') + op.drop_index(op.f('ix_polygon_transactions_type'), table_name='polygon_transactions') + op.drop_index(op.f('ix_polygon_transactions_to_address'), table_name='polygon_transactions') + op.drop_index(op.f('ix_polygon_transactions_selector'), table_name='polygon_transactions') + op.drop_index(op.f('ix_polygon_transactions_index'), table_name='polygon_transactions') + op.drop_index(op.f('ix_polygon_transactions_hash'), table_name='polygon_transactions') + op.drop_index(op.f('ix_polygon_transactions_from_address'), table_name='polygon_transactions') + op.drop_index(op.f('ix_polygon_transactions_block_number'), table_name='polygon_transactions') + op.drop_index(op.f('ix_polygon_transactions_block_hash'), table_name='polygon_transactions') + op.drop_table('polygon_transactions') + op.drop_index(op.f('ix_ethereum_transactions_type'), table_name='ethereum_transactions') + op.drop_index(op.f('ix_ethereum_transactions_to_address'), table_name='ethereum_transactions') + op.drop_index(op.f('ix_ethereum_transactions_selector'), table_name='ethereum_transactions') + op.drop_index(op.f('ix_ethereum_transactions_index'), table_name='ethereum_transactions') + op.drop_index(op.f('ix_ethereum_transactions_hash'), table_name='ethereum_transactions') + op.drop_index(op.f('ix_ethereum_transactions_from_address'), table_name='ethereum_transactions') + op.drop_index(op.f('ix_ethereum_transactions_block_number'), table_name='ethereum_transactions') + op.drop_index(op.f('ix_ethereum_transactions_block_hash'), table_name='ethereum_transactions') + op.drop_table('ethereum_transactions') + op.drop_index(op.f('ix_polygon_reorgs_block_number'), table_name='polygon_reorgs') + op.drop_index(op.f('ix_polygon_reorgs_block_hash'), table_name='polygon_reorgs') + op.drop_table('polygon_reorgs') + op.drop_index(op.f('ix_polygon_blocks_block_timestamp'), table_name='polygon_blocks') + op.drop_index(op.f('ix_polygon_blocks_block_number'), table_name='polygon_blocks') + op.drop_table('polygon_blocks') + op.drop_index(op.f('ix_ethereum_reorgs_block_number'), table_name='ethereum_reorgs') + op.drop_index(op.f('ix_ethereum_reorgs_block_hash'), table_name='ethereum_reorgs') + op.drop_table('ethereum_reorgs') + op.drop_index(op.f('ix_ethereum_blocks_block_timestamp'), table_name='ethereum_blocks') + op.drop_index(op.f('ix_ethereum_blocks_block_number'), table_name='ethereum_blocks') + op.drop_table('ethereum_blocks') + op.drop_index(op.f('ix_abi_jobs_user_id'), table_name='abi_jobs') + op.drop_index(op.f('ix_abi_jobs_status'), table_name='abi_jobs') + op.drop_index(op.f('ix_abi_jobs_historical_crawl_status'), table_name='abi_jobs') + op.drop_index(op.f('ix_abi_jobs_customer_id'), table_name='abi_jobs') + op.drop_index(op.f('ix_abi_jobs_chain'), table_name='abi_jobs') + op.drop_index(op.f('ix_abi_jobs_address'), table_name='abi_jobs') + op.drop_index(op.f('ix_abi_jobs_abi_selector'), table_name='abi_jobs') + op.drop_index(op.f('ix_abi_jobs_abi_name'), table_name='abi_jobs') + op.drop_table('abi_jobs') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/25b339f55f8f_add_b3.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/25b339f55f8f_add_b3.py new file mode 100644 index 0000000..578d082 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/25b339f55f8f_add_b3.py @@ -0,0 +1,139 @@ +"""add-b3 + +Revision ID: 25b339f55f8f +Revises: 48d2562504d1 +Create Date: 2024-09-11 13:58:54.884367 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "25b339f55f8f" +down_revision: Union[str, None] = "48d2562504d1" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "b3_blocks", + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("parent_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("block_number", name=op.f("pk_b3_blocks")), + ) + op.create_index( + op.f("ix_b3_blocks_block_number"), "b3_blocks", ["block_number"], unique=False + ) + op.create_index( + op.f("ix_b3_blocks_block_timestamp"), + "b3_blocks", + ["block_timestamp"], + unique=False, + ) + op.create_table( + "b3_reorgs", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_reorgs")), + ) + op.create_index( + op.f("ix_b3_reorgs_block_hash"), "b3_reorgs", ["block_hash"], unique=False + ) + op.create_index( + op.f("ix_b3_reorgs_block_number"), "b3_reorgs", ["block_number"], unique=False + ) + op.create_table( + "b3_sepolia_blocks", + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("parent_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("block_number", name=op.f("pk_b3_sepolia_blocks")), + ) + op.create_index( + op.f("ix_b3_sepolia_blocks_block_number"), + "b3_sepolia_blocks", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_blocks_block_timestamp"), + "b3_sepolia_blocks", + ["block_timestamp"], + unique=False, + ) + op.create_table( + "b3_sepolia_reorgs", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_sepolia_reorgs")), + ) + op.create_index( + op.f("ix_b3_sepolia_reorgs_block_hash"), + "b3_sepolia_reorgs", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_reorgs_block_number"), + "b3_sepolia_reorgs", + ["block_number"], + unique=False, + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + + op.drop_index( + op.f("ix_b3_sepolia_reorgs_block_number"), table_name="b3_sepolia_reorgs" + ) + op.drop_index( + op.f("ix_b3_sepolia_reorgs_block_hash"), table_name="b3_sepolia_reorgs" + ) + op.drop_table("b3_sepolia_reorgs") + op.drop_index( + op.f("ix_b3_sepolia_blocks_block_timestamp"), table_name="b3_sepolia_blocks" + ) + op.drop_index( + op.f("ix_b3_sepolia_blocks_block_number"), table_name="b3_sepolia_blocks" + ) + op.drop_table("b3_sepolia_blocks") + op.drop_index(op.f("ix_b3_reorgs_block_number"), table_name="b3_reorgs") + op.drop_index(op.f("ix_b3_reorgs_block_hash"), table_name="b3_reorgs") + op.drop_table("b3_reorgs") + op.drop_index(op.f("ix_b3_blocks_block_timestamp"), table_name="b3_blocks") + op.drop_index(op.f("ix_b3_blocks_block_number"), table_name="b3_blocks") + op.drop_table("b3_blocks") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/27086791044c_add_topic_3.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/27086791044c_add_topic_3.py new file mode 100644 index 0000000..6a61eb3 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/27086791044c_add_topic_3.py @@ -0,0 +1,68 @@ +"""Add topic 3 + +Revision ID: 27086791044c +Revises: e02c90ea67bb +Create Date: 2024-07-11 13:15:45.273275 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "27086791044c" +down_revision: Union[str, None] = "e02c90ea67bb" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "arbitrum_one_logs", sa.Column("topic3", sa.VARCHAR(length=256), nullable=True) + ) + op.add_column( + "arbitrum_sepolia_logs", + sa.Column("topic3", sa.VARCHAR(length=256), nullable=True), + ) + op.add_column( + "ethereum_logs", sa.Column("topic3", sa.VARCHAR(length=256), nullable=True) + ) + op.add_column( + "game7_orbit_arbitrum_sepolia_logs", + sa.Column("topic3", sa.VARCHAR(length=256), nullable=True), + ) + op.add_column( + "mantle_logs", sa.Column("topic3", sa.VARCHAR(length=256), nullable=True) + ) + op.add_column( + "mantle_sepolia_logs", + sa.Column("topic3", sa.VARCHAR(length=256), nullable=True), + ) + op.add_column( + "polygon_logs", sa.Column("topic3", sa.VARCHAR(length=256), nullable=True) + ) + op.add_column( + "xai_logs", sa.Column("topic3", sa.VARCHAR(length=256), nullable=True) + ) + op.add_column( + "xai_sepolia_logs", sa.Column("topic3", sa.VARCHAR(length=256), nullable=True) + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("xai_sepolia_logs", "topic3") + op.drop_column("xai_logs", "topic3") + op.drop_column("polygon_logs", "topic3") + op.drop_column("mantle_sepolia_logs", "topic3") + op.drop_column("mantle_logs", "topic3") + op.drop_column("game7_orbit_arbitrum_sepolia_logs", "topic3") + op.drop_column("ethereum_logs", "topic3") + op.drop_column("arbitrum_sepolia_logs", "topic3") + op.drop_column("arbitrum_one_logs", "topic3") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/48d2562504d1_add_indexed_at_logs_and_transactions.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/48d2562504d1_add_indexed_at_logs_and_transactions.py new file mode 100644 index 0000000..bc59350 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/48d2562504d1_add_indexed_at_logs_and_transactions.py @@ -0,0 +1,159 @@ +"""Add indexed_at logs and transactions + +Revision ID: 48d2562504d1 +Revises: b89a8affe2c3 +Create Date: 2024-08-20 17:08:34.493114 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "48d2562504d1" +down_revision: Union[str, None] = "b89a8affe2c3" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "arbitrum_one_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "arbitrum_one_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "arbitrum_sepolia_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "arbitrum_sepolia_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "ethereum_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "ethereum_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "game7_orbit_arbitrum_sepolia_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "game7_orbit_arbitrum_sepolia_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "game7_testnet_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "game7_testnet_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "imx_zkevm_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "imx_zkevm_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "imx_zkevm_sepolia_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "imx_zkevm_sepolia_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "mantle_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "mantle_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "mantle_sepolia_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "mantle_sepolia_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "polygon_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "polygon_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "sepolia_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "sepolia_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "xai_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "xai_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "xai_sepolia_blocks", + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "xai_sepolia_blocks", + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("xai_sepolia_blocks", "logs_indexed_at") + op.drop_column("xai_sepolia_blocks", "transactions_indexed_at") + op.drop_column("xai_blocks", "logs_indexed_at") + op.drop_column("xai_blocks", "transactions_indexed_at") + op.drop_column("sepolia_blocks", "logs_indexed_at") + op.drop_column("sepolia_blocks", "transactions_indexed_at") + op.drop_column("polygon_blocks", "logs_indexed_at") + op.drop_column("polygon_blocks", "transactions_indexed_at") + op.drop_column("mantle_sepolia_blocks", "logs_indexed_at") + op.drop_column("mantle_sepolia_blocks", "transactions_indexed_at") + op.drop_column("mantle_blocks", "logs_indexed_at") + op.drop_column("mantle_blocks", "transactions_indexed_at") + op.drop_column("imx_zkevm_sepolia_blocks", "logs_indexed_at") + op.drop_column("imx_zkevm_sepolia_blocks", "transactions_indexed_at") + op.drop_column("imx_zkevm_blocks", "logs_indexed_at") + op.drop_column("imx_zkevm_blocks", "transactions_indexed_at") + op.drop_column("game7_testnet_blocks", "logs_indexed_at") + op.drop_column("game7_testnet_blocks", "transactions_indexed_at") + op.drop_column("game7_orbit_arbitrum_sepolia_blocks", "logs_indexed_at") + op.drop_column("game7_orbit_arbitrum_sepolia_blocks", "transactions_indexed_at") + op.drop_column("ethereum_blocks", "logs_indexed_at") + op.drop_column("ethereum_blocks", "transactions_indexed_at") + op.drop_column("arbitrum_sepolia_blocks", "logs_indexed_at") + op.drop_column("arbitrum_sepolia_blocks", "transactions_indexed_at") + op.drop_column("arbitrum_one_blocks", "logs_indexed_at") + op.drop_column("arbitrum_one_blocks", "transactions_indexed_at") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/6807bdf6f417_add_deploy_block.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/6807bdf6f417_add_deploy_block.py new file mode 100644 index 0000000..8b58872 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/6807bdf6f417_add_deploy_block.py @@ -0,0 +1,34 @@ +"""Add deploy block + +Revision ID: 6807bdf6f417 +Revises: 48d2562504d1 +Create Date: 2024-08-23 16:51:47.147758 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "6807bdf6f417" +down_revision: Union[str, None] = "25b339f55f8f" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "abi_jobs", + sa.Column("deployment_block_number", sa.BigInteger(), nullable=True), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("abi_jobs", "deployment_block_number") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/__init__.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py new file mode 100644 index 0000000..5bb9c5f --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py @@ -0,0 +1,276 @@ +"""Add sepolia + +Revision ID: a1ead76c0470 +Revises: f2c6aa92e5d2 +Create Date: 2024-07-22 14:07:22.992523 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "a1ead76c0470" +down_revision: Union[str, None] = "f2c6aa92e5d2" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "sepolia_blocks", + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("parent_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("block_number", name=op.f("pk_sepolia_blocks")), + ) + op.create_index( + op.f("ix_sepolia_blocks_block_number"), + "sepolia_blocks", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_blocks_block_timestamp"), + "sepolia_blocks", + ["block_timestamp"], + unique=False, + ) + op.create_table( + "sepolia_reorgs", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint("id", name=op.f("pk_sepolia_reorgs")), + ) + op.create_index( + op.f("ix_sepolia_reorgs_block_hash"), + "sepolia_reorgs", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_reorgs_block_number"), + "sepolia_reorgs", + ["block_number"], + unique=False, + ) + op.create_table( + "sepolia_transactions", + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("from_address", sa.LargeBinary(length=20), nullable=False), + sa.Column("to_address", sa.LargeBinary(length=20), nullable=False), + sa.Column("selector", sa.VARCHAR(length=256), nullable=True), + sa.Column("type", sa.Integer(), nullable=True), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("index", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.ForeignKeyConstraint( + ["block_number"], + ["sepolia_blocks.block_number"], + name=op.f("fk_sepolia_transactions_block_number_sepolia_blocks"), + ondelete="CASCADE", + ), + sa.PrimaryKeyConstraint("hash", name=op.f("pk_sepolia_transactions")), + ) + op.create_index( + op.f("ix_sepolia_transactions_block_hash"), + "sepolia_transactions", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_transactions_block_number"), + "sepolia_transactions", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_transactions_from_address"), + "sepolia_transactions", + ["from_address"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_transactions_hash"), + "sepolia_transactions", + ["hash"], + unique=True, + ) + op.create_index( + op.f("ix_sepolia_transactions_index"), + "sepolia_transactions", + ["index"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_transactions_selector"), + "sepolia_transactions", + ["selector"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_transactions_to_address"), + "sepolia_transactions", + ["to_address"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_transactions_type"), + "sepolia_transactions", + ["type"], + unique=False, + ) + op.create_table( + "sepolia_logs", + sa.Column("transaction_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("address", sa.LargeBinary(length=20), nullable=False), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("selector", sa.VARCHAR(length=256), nullable=True), + sa.Column("topic1", sa.VARCHAR(length=256), nullable=True), + sa.Column("topic2", sa.VARCHAR(length=256), nullable=True), + sa.Column("topic3", sa.VARCHAR(length=256), nullable=True), + sa.Column("log_index", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.ForeignKeyConstraint( + ["transaction_hash"], + ["sepolia_transactions.hash"], + name=op.f("fk_sepolia_logs_transaction_hash_sepolia_transactions"), + ondelete="CASCADE", + ), + sa.PrimaryKeyConstraint( + "transaction_hash", "log_index", name="pk_sepolia_log_index" + ), + sa.UniqueConstraint( + "transaction_hash", + "log_index", + name="uq_sepolia_log_index_transaction_hash_log_index", + ), + ) + op.create_index( + "idx_sepolia_logs_address_selector", + "sepolia_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_sepolia_logs_block_hash_log_index", + "sepolia_logs", + ["block_hash", "log_index"], + unique=True, + ) + op.create_index( + op.f("ix_sepolia_logs_address"), + "sepolia_logs", + ["address"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_logs_block_hash"), + "sepolia_logs", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_sepolia_logs_transaction_hash"), + "sepolia_logs", + ["transaction_hash"], + unique=False, + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + op.f("ix_sepolia_logs_transaction_hash"), + table_name="sepolia_logs", + ) + op.drop_index(op.f("ix_sepolia_logs_block_hash"), table_name="sepolia_logs") + op.drop_index(op.f("ix_sepolia_logs_address"), table_name="sepolia_logs") + op.drop_index( + "idx_sepolia_logs_block_hash_log_index", + table_name="sepolia_logs", + ) + op.drop_index("idx_sepolia_logs_address_selector", table_name="sepolia_logs") + op.drop_table("sepolia_logs") + op.drop_index( + op.f("ix_sepolia_transactions_type"), + table_name="sepolia_transactions", + ) + op.drop_index( + op.f("ix_sepolia_transactions_to_address"), + table_name="sepolia_transactions", + ) + op.drop_index( + op.f("ix_sepolia_transactions_selector"), + table_name="sepolia_transactions", + ) + op.drop_index( + op.f("ix_sepolia_transactions_index"), + table_name="sepolia_transactions", + ) + op.drop_index( + op.f("ix_sepolia_transactions_hash"), + table_name="sepolia_transactions", + ) + op.drop_index( + op.f("ix_sepolia_transactions_from_address"), + table_name="sepolia_transactions", + ) + op.drop_index( + op.f("ix_sepolia_transactions_block_number"), + table_name="sepolia_transactions", + ) + op.drop_index( + op.f("ix_sepolia_transactions_block_hash"), + table_name="sepolia_transactions", + ) + op.drop_table("sepolia_transactions") + op.drop_index( + op.f("ix_sepolia_reorgs_block_number"), + table_name="sepolia_reorgs", + ) + op.drop_index( + op.f("ix_sepolia_reorgs_block_hash"), + table_name="sepolia_reorgs", + ) + op.drop_table("sepolia_reorgs") + op.drop_index( + op.f("ix_sepolia_blocks_block_timestamp"), + table_name="sepolia_blocks", + ) + op.drop_index( + op.f("ix_sepolia_blocks_block_number"), + table_name="sepolia_blocks", + ) + op.drop_table("sepolia_blocks") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a4ef4f9031e4_game7_orbit_arbitrum_xai_and_mantle_.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a4ef4f9031e4_game7_orbit_arbitrum_xai_and_mantle_.py new file mode 100644 index 0000000..201be7e --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a4ef4f9031e4_game7_orbit_arbitrum_xai_and_mantle_.py @@ -0,0 +1,597 @@ +"""Game7 Orbit, Arbitrum, Xai and Mantle blockchain indexes models + +Revision ID: a4ef4f9031e4 +Revises: 0ea24314c181 +Create Date: 2024-05-29 13:19:42.833716 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'a4ef4f9031e4' +down_revision: Union[str, None] = '0ea24314c181' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('arbitrum_one_blocks', + sa.Column('l1_block_number', sa.BigInteger(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_arbitrum_one_blocks')) + ) + op.create_index(op.f('ix_arbitrum_one_blocks_block_number'), 'arbitrum_one_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_one_blocks_block_timestamp'), 'arbitrum_one_blocks', ['block_timestamp'], unique=False) + op.create_table('arbitrum_one_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_arbitrum_one_reorgs')) + ) + op.create_index(op.f('ix_arbitrum_one_reorgs_block_hash'), 'arbitrum_one_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_arbitrum_one_reorgs_block_number'), 'arbitrum_one_reorgs', ['block_number'], unique=False) + op.create_table('arbitrum_sepolia_blocks', + sa.Column('l1_block_number', sa.BigInteger(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_arbitrum_sepolia_blocks')) + ) + op.create_index(op.f('ix_arbitrum_sepolia_blocks_block_number'), 'arbitrum_sepolia_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_blocks_block_timestamp'), 'arbitrum_sepolia_blocks', ['block_timestamp'], unique=False) + op.create_table('arbitrum_sepolia_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_arbitrum_sepolia_reorgs')) + ) + op.create_index(op.f('ix_arbitrum_sepolia_reorgs_block_hash'), 'arbitrum_sepolia_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_reorgs_block_number'), 'arbitrum_sepolia_reorgs', ['block_number'], unique=False) + op.create_table('game7_orbit_arbitrum_sepolia_blocks', + sa.Column('l1_block_number', sa.BigInteger(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_game7_orbit_arbitrum_sepolia_blocks')) + ) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_blocks_block_number'), 'game7_orbit_arbitrum_sepolia_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_blocks_block_timestamp'), 'game7_orbit_arbitrum_sepolia_blocks', ['block_timestamp'], unique=False) + op.create_table('game7_orbit_arbitrum_sepolia_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_game7_orbit_arbitrum_sepolia_reorgs')) + ) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_reorgs_block_hash'), 'game7_orbit_arbitrum_sepolia_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_reorgs_block_number'), 'game7_orbit_arbitrum_sepolia_reorgs', ['block_number'], unique=False) + op.create_table('mantle_blocks', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_mantle_blocks')) + ) + op.create_index(op.f('ix_mantle_blocks_block_number'), 'mantle_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_mantle_blocks_block_timestamp'), 'mantle_blocks', ['block_timestamp'], unique=False) + op.create_table('mantle_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_mantle_reorgs')) + ) + op.create_index(op.f('ix_mantle_reorgs_block_hash'), 'mantle_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_mantle_reorgs_block_number'), 'mantle_reorgs', ['block_number'], unique=False) + op.create_table('mantle_sepolia_blocks', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_mantle_sepolia_blocks')) + ) + op.create_index(op.f('ix_mantle_sepolia_blocks_block_number'), 'mantle_sepolia_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_blocks_block_timestamp'), 'mantle_sepolia_blocks', ['block_timestamp'], unique=False) + op.create_table('mantle_sepolia_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_mantle_sepolia_reorgs')) + ) + op.create_index(op.f('ix_mantle_sepolia_reorgs_block_hash'), 'mantle_sepolia_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_reorgs_block_number'), 'mantle_sepolia_reorgs', ['block_number'], unique=False) + op.create_table('xai_blocks', + sa.Column('l1_block_number', sa.BigInteger(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_xai_blocks')) + ) + op.create_index(op.f('ix_xai_blocks_block_number'), 'xai_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_xai_blocks_block_timestamp'), 'xai_blocks', ['block_timestamp'], unique=False) + op.create_table('xai_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_xai_reorgs')) + ) + op.create_index(op.f('ix_xai_reorgs_block_hash'), 'xai_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_xai_reorgs_block_number'), 'xai_reorgs', ['block_number'], unique=False) + op.create_table('xai_sepolia_blocks', + sa.Column('l1_block_number', sa.BigInteger(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_xai_sepolia_blocks')) + ) + op.create_index(op.f('ix_xai_sepolia_blocks_block_number'), 'xai_sepolia_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_xai_sepolia_blocks_block_timestamp'), 'xai_sepolia_blocks', ['block_timestamp'], unique=False) + op.create_table('xai_sepolia_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_xai_sepolia_reorgs')) + ) + op.create_index(op.f('ix_xai_sepolia_reorgs_block_hash'), 'xai_sepolia_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_xai_sepolia_reorgs_block_number'), 'xai_sepolia_reorgs', ['block_number'], unique=False) + op.create_table('arbitrum_one_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['arbitrum_one_blocks.block_number'], name=op.f('fk_arbitrum_one_transactions_block_number_arbitrum_one_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_arbitrum_one_transactions')) + ) + op.create_index(op.f('ix_arbitrum_one_transactions_block_hash'), 'arbitrum_one_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_arbitrum_one_transactions_block_number'), 'arbitrum_one_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_one_transactions_from_address'), 'arbitrum_one_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_arbitrum_one_transactions_hash'), 'arbitrum_one_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_arbitrum_one_transactions_index'), 'arbitrum_one_transactions', ['index'], unique=False) + op.create_index(op.f('ix_arbitrum_one_transactions_selector'), 'arbitrum_one_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_arbitrum_one_transactions_to_address'), 'arbitrum_one_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_arbitrum_one_transactions_type'), 'arbitrum_one_transactions', ['type'], unique=False) + op.create_table('arbitrum_sepolia_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['arbitrum_sepolia_blocks.block_number'], name=op.f('fk_arbitrum_sepolia_transactions_block_number_arbitrum_sepolia_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_arbitrum_sepolia_transactions')) + ) + op.create_index(op.f('ix_arbitrum_sepolia_transactions_block_hash'), 'arbitrum_sepolia_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_transactions_block_number'), 'arbitrum_sepolia_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_transactions_from_address'), 'arbitrum_sepolia_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_transactions_hash'), 'arbitrum_sepolia_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_arbitrum_sepolia_transactions_index'), 'arbitrum_sepolia_transactions', ['index'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_transactions_selector'), 'arbitrum_sepolia_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_transactions_to_address'), 'arbitrum_sepolia_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_transactions_type'), 'arbitrum_sepolia_transactions', ['type'], unique=False) + op.create_table('game7_orbit_arbitrum_sepolia_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['game7_orbit_arbitrum_sepolia_blocks.block_number'], name=op.f('fk_game7_orbit_arbitrum_sepolia_transactions_block_number_game7_orbit_arbitrum_sepolia_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_game7_orbit_arbitrum_sepolia_transactions')) + ) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_block_hash'), 'game7_orbit_arbitrum_sepolia_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_block_number'), 'game7_orbit_arbitrum_sepolia_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_from_address'), 'game7_orbit_arbitrum_sepolia_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_hash'), 'game7_orbit_arbitrum_sepolia_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_index'), 'game7_orbit_arbitrum_sepolia_transactions', ['index'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_selector'), 'game7_orbit_arbitrum_sepolia_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_to_address'), 'game7_orbit_arbitrum_sepolia_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_type'), 'game7_orbit_arbitrum_sepolia_transactions', ['type'], unique=False) + op.create_table('mantle_sepolia_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['mantle_sepolia_blocks.block_number'], name=op.f('fk_mantle_sepolia_transactions_block_number_mantle_sepolia_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_mantle_sepolia_transactions')) + ) + op.create_index(op.f('ix_mantle_sepolia_transactions_block_hash'), 'mantle_sepolia_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_transactions_block_number'), 'mantle_sepolia_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_transactions_from_address'), 'mantle_sepolia_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_transactions_hash'), 'mantle_sepolia_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_mantle_sepolia_transactions_index'), 'mantle_sepolia_transactions', ['index'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_transactions_selector'), 'mantle_sepolia_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_transactions_to_address'), 'mantle_sepolia_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_transactions_type'), 'mantle_sepolia_transactions', ['type'], unique=False) + op.create_table('mantle_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['mantle_blocks.block_number'], name=op.f('fk_mantle_transactions_block_number_mantle_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_mantle_transactions')) + ) + op.create_index(op.f('ix_mantle_transactions_block_hash'), 'mantle_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_mantle_transactions_block_number'), 'mantle_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_mantle_transactions_from_address'), 'mantle_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_mantle_transactions_hash'), 'mantle_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_mantle_transactions_index'), 'mantle_transactions', ['index'], unique=False) + op.create_index(op.f('ix_mantle_transactions_selector'), 'mantle_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_mantle_transactions_to_address'), 'mantle_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_mantle_transactions_type'), 'mantle_transactions', ['type'], unique=False) + op.create_table('xai_sepolia_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['xai_sepolia_blocks.block_number'], name=op.f('fk_xai_sepolia_transactions_block_number_xai_sepolia_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_xai_sepolia_transactions')) + ) + op.create_index(op.f('ix_xai_sepolia_transactions_block_hash'), 'xai_sepolia_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_xai_sepolia_transactions_block_number'), 'xai_sepolia_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_xai_sepolia_transactions_from_address'), 'xai_sepolia_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_xai_sepolia_transactions_hash'), 'xai_sepolia_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_xai_sepolia_transactions_index'), 'xai_sepolia_transactions', ['index'], unique=False) + op.create_index(op.f('ix_xai_sepolia_transactions_selector'), 'xai_sepolia_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_xai_sepolia_transactions_to_address'), 'xai_sepolia_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_xai_sepolia_transactions_type'), 'xai_sepolia_transactions', ['type'], unique=False) + op.create_table('xai_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['xai_blocks.block_number'], name=op.f('fk_xai_transactions_block_number_xai_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_xai_transactions')) + ) + op.create_index(op.f('ix_xai_transactions_block_hash'), 'xai_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_xai_transactions_block_number'), 'xai_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_xai_transactions_from_address'), 'xai_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_xai_transactions_hash'), 'xai_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_xai_transactions_index'), 'xai_transactions', ['index'], unique=False) + op.create_index(op.f('ix_xai_transactions_selector'), 'xai_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_xai_transactions_to_address'), 'xai_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_xai_transactions_type'), 'xai_transactions', ['type'], unique=False) + op.create_table('arbitrum_one_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['arbitrum_one_transactions.hash'], name=op.f('fk_arbitrum_one_logs_transaction_hash_arbitrum_one_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_arbitrum_one_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_arbitrum_one_log_idx_tx_hash_log_idx') + ) + op.create_index(op.f('ix_arbitrum_one_logs_address'), 'arbitrum_one_logs', ['address'], unique=False) + op.create_index(op.f('ix_arbitrum_one_logs_block_hash'), 'arbitrum_one_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_arbitrum_one_logs_transaction_hash'), 'arbitrum_one_logs', ['transaction_hash'], unique=False) + op.create_table('arbitrum_sepolia_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['arbitrum_sepolia_transactions.hash'], name=op.f('fk_arbitrum_sepolia_logs_transaction_hash_arbitrum_sepolia_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_arbitrum_sepolia_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_arbitrum_sepolia_log_idx_tx_hash_log_idx') + ) + op.create_index(op.f('ix_arbitrum_sepolia_logs_address'), 'arbitrum_sepolia_logs', ['address'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_logs_block_hash'), 'arbitrum_sepolia_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_logs_transaction_hash'), 'arbitrum_sepolia_logs', ['transaction_hash'], unique=False) + op.create_table('game7_orbit_arbitrum_sepolia_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['game7_orbit_arbitrum_sepolia_transactions.hash'], name=op.f('fk_game7_orbit_arbitrum_sepolia_logs_transaction_hash_game7_orbit_arbitrum_sepolia_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_game7_orbit_arbitrum_sepolia_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_g7o_arbitrum_sepolia_log_idx_tx_hash_log_idx') + ) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_logs_address'), 'game7_orbit_arbitrum_sepolia_logs', ['address'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_logs_block_hash'), 'game7_orbit_arbitrum_sepolia_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_game7_orbit_arbitrum_sepolia_logs_transaction_hash'), 'game7_orbit_arbitrum_sepolia_logs', ['transaction_hash'], unique=False) + op.create_table('mantle_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['mantle_transactions.hash'], name=op.f('fk_mantle_logs_transaction_hash_mantle_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_mantle_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_mantle_log_index_transaction_hash_log_index') + ) + op.create_index('idx_mantle_logs_block_hash_log_index', 'mantle_logs', ['block_hash', 'log_index'], unique=True) + op.create_index(op.f('ix_mantle_logs_address'), 'mantle_logs', ['address'], unique=False) + op.create_index(op.f('ix_mantle_logs_block_hash'), 'mantle_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_mantle_logs_transaction_hash'), 'mantle_logs', ['transaction_hash'], unique=False) + op.create_table('mantle_sepolia_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['mantle_sepolia_transactions.hash'], name=op.f('fk_mantle_sepolia_logs_transaction_hash_mantle_sepolia_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_mantle_sepolia_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_mantle_sepolia_log_index_transaction_hash_log_index') + ) + op.create_index('idx_mantle_sepolia_logs_block_hash_log_index', 'mantle_sepolia_logs', ['block_hash', 'log_index'], unique=True) + op.create_index(op.f('ix_mantle_sepolia_logs_address'), 'mantle_sepolia_logs', ['address'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_logs_block_hash'), 'mantle_sepolia_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_mantle_sepolia_logs_transaction_hash'), 'mantle_sepolia_logs', ['transaction_hash'], unique=False) + op.create_table('xai_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['xai_transactions.hash'], name=op.f('fk_xai_logs_transaction_hash_xai_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_xai_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_xai_log_idx_tx_hash_log_idx') + ) + op.create_index(op.f('ix_xai_logs_address'), 'xai_logs', ['address'], unique=False) + op.create_index(op.f('ix_xai_logs_block_hash'), 'xai_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_xai_logs_transaction_hash'), 'xai_logs', ['transaction_hash'], unique=False) + op.create_table('xai_sepolia_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['xai_sepolia_transactions.hash'], name=op.f('fk_xai_sepolia_logs_transaction_hash_xai_sepolia_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_xai_sepolia_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_xai_sepolia_log_idx_tx_hash_log_idx') + ) + op.create_index(op.f('ix_xai_sepolia_logs_address'), 'xai_sepolia_logs', ['address'], unique=False) + op.create_index(op.f('ix_xai_sepolia_logs_block_hash'), 'xai_sepolia_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_xai_sepolia_logs_transaction_hash'), 'xai_sepolia_logs', ['transaction_hash'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_xai_sepolia_logs_transaction_hash'), table_name='xai_sepolia_logs') + op.drop_index(op.f('ix_xai_sepolia_logs_block_hash'), table_name='xai_sepolia_logs') + op.drop_index(op.f('ix_xai_sepolia_logs_address'), table_name='xai_sepolia_logs') + op.drop_table('xai_sepolia_logs') + op.drop_index(op.f('ix_xai_logs_transaction_hash'), table_name='xai_logs') + op.drop_index(op.f('ix_xai_logs_block_hash'), table_name='xai_logs') + op.drop_index(op.f('ix_xai_logs_address'), table_name='xai_logs') + op.drop_table('xai_logs') + op.drop_index(op.f('ix_mantle_sepolia_logs_transaction_hash'), table_name='mantle_sepolia_logs') + op.drop_index(op.f('ix_mantle_sepolia_logs_block_hash'), table_name='mantle_sepolia_logs') + op.drop_index(op.f('ix_mantle_sepolia_logs_address'), table_name='mantle_sepolia_logs') + op.drop_index('idx_mantle_sepolia_logs_block_hash_log_index', table_name='mantle_sepolia_logs') + op.drop_table('mantle_sepolia_logs') + op.drop_index(op.f('ix_mantle_logs_transaction_hash'), table_name='mantle_logs') + op.drop_index(op.f('ix_mantle_logs_block_hash'), table_name='mantle_logs') + op.drop_index(op.f('ix_mantle_logs_address'), table_name='mantle_logs') + op.drop_index('idx_mantle_logs_block_hash_log_index', table_name='mantle_logs') + op.drop_table('mantle_logs') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_logs_transaction_hash'), table_name='game7_orbit_arbitrum_sepolia_logs') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_logs_block_hash'), table_name='game7_orbit_arbitrum_sepolia_logs') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_logs_address'), table_name='game7_orbit_arbitrum_sepolia_logs') + op.drop_table('game7_orbit_arbitrum_sepolia_logs') + op.drop_index(op.f('ix_arbitrum_sepolia_logs_transaction_hash'), table_name='arbitrum_sepolia_logs') + op.drop_index(op.f('ix_arbitrum_sepolia_logs_block_hash'), table_name='arbitrum_sepolia_logs') + op.drop_index(op.f('ix_arbitrum_sepolia_logs_address'), table_name='arbitrum_sepolia_logs') + op.drop_table('arbitrum_sepolia_logs') + op.drop_index(op.f('ix_arbitrum_one_logs_transaction_hash'), table_name='arbitrum_one_logs') + op.drop_index(op.f('ix_arbitrum_one_logs_block_hash'), table_name='arbitrum_one_logs') + op.drop_index(op.f('ix_arbitrum_one_logs_address'), table_name='arbitrum_one_logs') + op.drop_table('arbitrum_one_logs') + op.drop_index(op.f('ix_xai_transactions_type'), table_name='xai_transactions') + op.drop_index(op.f('ix_xai_transactions_to_address'), table_name='xai_transactions') + op.drop_index(op.f('ix_xai_transactions_selector'), table_name='xai_transactions') + op.drop_index(op.f('ix_xai_transactions_index'), table_name='xai_transactions') + op.drop_index(op.f('ix_xai_transactions_hash'), table_name='xai_transactions') + op.drop_index(op.f('ix_xai_transactions_from_address'), table_name='xai_transactions') + op.drop_index(op.f('ix_xai_transactions_block_number'), table_name='xai_transactions') + op.drop_index(op.f('ix_xai_transactions_block_hash'), table_name='xai_transactions') + op.drop_table('xai_transactions') + op.drop_index(op.f('ix_xai_sepolia_transactions_type'), table_name='xai_sepolia_transactions') + op.drop_index(op.f('ix_xai_sepolia_transactions_to_address'), table_name='xai_sepolia_transactions') + op.drop_index(op.f('ix_xai_sepolia_transactions_selector'), table_name='xai_sepolia_transactions') + op.drop_index(op.f('ix_xai_sepolia_transactions_index'), table_name='xai_sepolia_transactions') + op.drop_index(op.f('ix_xai_sepolia_transactions_hash'), table_name='xai_sepolia_transactions') + op.drop_index(op.f('ix_xai_sepolia_transactions_from_address'), table_name='xai_sepolia_transactions') + op.drop_index(op.f('ix_xai_sepolia_transactions_block_number'), table_name='xai_sepolia_transactions') + op.drop_index(op.f('ix_xai_sepolia_transactions_block_hash'), table_name='xai_sepolia_transactions') + op.drop_table('xai_sepolia_transactions') + op.drop_index(op.f('ix_mantle_transactions_type'), table_name='mantle_transactions') + op.drop_index(op.f('ix_mantle_transactions_to_address'), table_name='mantle_transactions') + op.drop_index(op.f('ix_mantle_transactions_selector'), table_name='mantle_transactions') + op.drop_index(op.f('ix_mantle_transactions_index'), table_name='mantle_transactions') + op.drop_index(op.f('ix_mantle_transactions_hash'), table_name='mantle_transactions') + op.drop_index(op.f('ix_mantle_transactions_from_address'), table_name='mantle_transactions') + op.drop_index(op.f('ix_mantle_transactions_block_number'), table_name='mantle_transactions') + op.drop_index(op.f('ix_mantle_transactions_block_hash'), table_name='mantle_transactions') + op.drop_table('mantle_transactions') + op.drop_index(op.f('ix_mantle_sepolia_transactions_type'), table_name='mantle_sepolia_transactions') + op.drop_index(op.f('ix_mantle_sepolia_transactions_to_address'), table_name='mantle_sepolia_transactions') + op.drop_index(op.f('ix_mantle_sepolia_transactions_selector'), table_name='mantle_sepolia_transactions') + op.drop_index(op.f('ix_mantle_sepolia_transactions_index'), table_name='mantle_sepolia_transactions') + op.drop_index(op.f('ix_mantle_sepolia_transactions_hash'), table_name='mantle_sepolia_transactions') + op.drop_index(op.f('ix_mantle_sepolia_transactions_from_address'), table_name='mantle_sepolia_transactions') + op.drop_index(op.f('ix_mantle_sepolia_transactions_block_number'), table_name='mantle_sepolia_transactions') + op.drop_index(op.f('ix_mantle_sepolia_transactions_block_hash'), table_name='mantle_sepolia_transactions') + op.drop_table('mantle_sepolia_transactions') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_type'), table_name='game7_orbit_arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_to_address'), table_name='game7_orbit_arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_selector'), table_name='game7_orbit_arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_index'), table_name='game7_orbit_arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_hash'), table_name='game7_orbit_arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_from_address'), table_name='game7_orbit_arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_block_number'), table_name='game7_orbit_arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_transactions_block_hash'), table_name='game7_orbit_arbitrum_sepolia_transactions') + op.drop_table('game7_orbit_arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_arbitrum_sepolia_transactions_type'), table_name='arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_arbitrum_sepolia_transactions_to_address'), table_name='arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_arbitrum_sepolia_transactions_selector'), table_name='arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_arbitrum_sepolia_transactions_index'), table_name='arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_arbitrum_sepolia_transactions_hash'), table_name='arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_arbitrum_sepolia_transactions_from_address'), table_name='arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_arbitrum_sepolia_transactions_block_number'), table_name='arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_arbitrum_sepolia_transactions_block_hash'), table_name='arbitrum_sepolia_transactions') + op.drop_table('arbitrum_sepolia_transactions') + op.drop_index(op.f('ix_arbitrum_one_transactions_type'), table_name='arbitrum_one_transactions') + op.drop_index(op.f('ix_arbitrum_one_transactions_to_address'), table_name='arbitrum_one_transactions') + op.drop_index(op.f('ix_arbitrum_one_transactions_selector'), table_name='arbitrum_one_transactions') + op.drop_index(op.f('ix_arbitrum_one_transactions_index'), table_name='arbitrum_one_transactions') + op.drop_index(op.f('ix_arbitrum_one_transactions_hash'), table_name='arbitrum_one_transactions') + op.drop_index(op.f('ix_arbitrum_one_transactions_from_address'), table_name='arbitrum_one_transactions') + op.drop_index(op.f('ix_arbitrum_one_transactions_block_number'), table_name='arbitrum_one_transactions') + op.drop_index(op.f('ix_arbitrum_one_transactions_block_hash'), table_name='arbitrum_one_transactions') + op.drop_table('arbitrum_one_transactions') + op.drop_index(op.f('ix_xai_sepolia_reorgs_block_number'), table_name='xai_sepolia_reorgs') + op.drop_index(op.f('ix_xai_sepolia_reorgs_block_hash'), table_name='xai_sepolia_reorgs') + op.drop_table('xai_sepolia_reorgs') + op.drop_index(op.f('ix_xai_sepolia_blocks_block_timestamp'), table_name='xai_sepolia_blocks') + op.drop_index(op.f('ix_xai_sepolia_blocks_block_number'), table_name='xai_sepolia_blocks') + op.drop_table('xai_sepolia_blocks') + op.drop_index(op.f('ix_xai_reorgs_block_number'), table_name='xai_reorgs') + op.drop_index(op.f('ix_xai_reorgs_block_hash'), table_name='xai_reorgs') + op.drop_table('xai_reorgs') + op.drop_index(op.f('ix_xai_blocks_block_timestamp'), table_name='xai_blocks') + op.drop_index(op.f('ix_xai_blocks_block_number'), table_name='xai_blocks') + op.drop_table('xai_blocks') + op.drop_index(op.f('ix_mantle_sepolia_reorgs_block_number'), table_name='mantle_sepolia_reorgs') + op.drop_index(op.f('ix_mantle_sepolia_reorgs_block_hash'), table_name='mantle_sepolia_reorgs') + op.drop_table('mantle_sepolia_reorgs') + op.drop_index(op.f('ix_mantle_sepolia_blocks_block_timestamp'), table_name='mantle_sepolia_blocks') + op.drop_index(op.f('ix_mantle_sepolia_blocks_block_number'), table_name='mantle_sepolia_blocks') + op.drop_table('mantle_sepolia_blocks') + op.drop_index(op.f('ix_mantle_reorgs_block_number'), table_name='mantle_reorgs') + op.drop_index(op.f('ix_mantle_reorgs_block_hash'), table_name='mantle_reorgs') + op.drop_table('mantle_reorgs') + op.drop_index(op.f('ix_mantle_blocks_block_timestamp'), table_name='mantle_blocks') + op.drop_index(op.f('ix_mantle_blocks_block_number'), table_name='mantle_blocks') + op.drop_table('mantle_blocks') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_reorgs_block_number'), table_name='game7_orbit_arbitrum_sepolia_reorgs') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_reorgs_block_hash'), table_name='game7_orbit_arbitrum_sepolia_reorgs') + op.drop_table('game7_orbit_arbitrum_sepolia_reorgs') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_blocks_block_timestamp'), table_name='game7_orbit_arbitrum_sepolia_blocks') + op.drop_index(op.f('ix_game7_orbit_arbitrum_sepolia_blocks_block_number'), table_name='game7_orbit_arbitrum_sepolia_blocks') + op.drop_table('game7_orbit_arbitrum_sepolia_blocks') + op.drop_index(op.f('ix_arbitrum_sepolia_reorgs_block_number'), table_name='arbitrum_sepolia_reorgs') + op.drop_index(op.f('ix_arbitrum_sepolia_reorgs_block_hash'), table_name='arbitrum_sepolia_reorgs') + op.drop_table('arbitrum_sepolia_reorgs') + op.drop_index(op.f('ix_arbitrum_sepolia_blocks_block_timestamp'), table_name='arbitrum_sepolia_blocks') + op.drop_index(op.f('ix_arbitrum_sepolia_blocks_block_number'), table_name='arbitrum_sepolia_blocks') + op.drop_table('arbitrum_sepolia_blocks') + op.drop_index(op.f('ix_arbitrum_one_reorgs_block_number'), table_name='arbitrum_one_reorgs') + op.drop_index(op.f('ix_arbitrum_one_reorgs_block_hash'), table_name='arbitrum_one_reorgs') + op.drop_table('arbitrum_one_reorgs') + op.drop_index(op.f('ix_arbitrum_one_blocks_block_timestamp'), table_name='arbitrum_one_blocks') + op.drop_index(op.f('ix_arbitrum_one_blocks_block_number'), table_name='arbitrum_one_blocks') + op.drop_table('arbitrum_one_blocks') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/b89a8affe2c3_add_game7_testnet.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/b89a8affe2c3_add_game7_testnet.py new file mode 100644 index 0000000..76f1bdc --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/b89a8affe2c3_add_game7_testnet.py @@ -0,0 +1,273 @@ +"""Add game7 testnet + +Revision ID: b89a8affe2c3 +Revises: f19652e59bc5 +Create Date: 2024-08-05 16:29:33.091636 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "b89a8affe2c3" +down_revision: Union[str, None] = "f19652e59bc5" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "game7_testnet_blocks", + sa.Column("l1_block_number", sa.BigInteger(), nullable=False), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("parent_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("block_number", name=op.f("pk_game7_testnet_blocks")), + ) + op.create_index( + op.f("ix_game7_testnet_blocks_block_number"), + "game7_testnet_blocks", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_blocks_block_timestamp"), + "game7_testnet_blocks", + ["block_timestamp"], + unique=False, + ) + op.create_table( + "game7_testnet_reorgs", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint("id", name=op.f("pk_game7_testnet_reorgs")), + ) + op.create_index( + op.f("ix_game7_testnet_reorgs_block_hash"), + "game7_testnet_reorgs", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_reorgs_block_number"), + "game7_testnet_reorgs", + ["block_number"], + unique=False, + ) + op.create_table( + "game7_testnet_transactions", + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("from_address", sa.LargeBinary(length=20), nullable=False), + sa.Column("to_address", sa.LargeBinary(length=20), nullable=False), + sa.Column("selector", sa.VARCHAR(length=256), nullable=True), + sa.Column("type", sa.Integer(), nullable=True), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("index", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.ForeignKeyConstraint( + ["block_number"], + ["game7_testnet_blocks.block_number"], + name=op.f( + "fk_game7_testnet_transactions_block_number_game7_testnet_blocks" + ), + ondelete="CASCADE", + ), + sa.PrimaryKeyConstraint("hash", name=op.f("pk_game7_testnet_transactions")), + ) + op.create_index( + op.f("ix_game7_testnet_transactions_block_hash"), + "game7_testnet_transactions", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_transactions_block_number"), + "game7_testnet_transactions", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_transactions_from_address"), + "game7_testnet_transactions", + ["from_address"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_transactions_hash"), + "game7_testnet_transactions", + ["hash"], + unique=True, + ) + op.create_index( + op.f("ix_game7_testnet_transactions_index"), + "game7_testnet_transactions", + ["index"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_transactions_selector"), + "game7_testnet_transactions", + ["selector"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_transactions_to_address"), + "game7_testnet_transactions", + ["to_address"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_transactions_type"), + "game7_testnet_transactions", + ["type"], + unique=False, + ) + op.create_table( + "game7_testnet_logs", + sa.Column("transaction_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("address", sa.LargeBinary(length=20), nullable=False), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("selector", sa.VARCHAR(length=256), nullable=True), + sa.Column("topic1", sa.VARCHAR(length=256), nullable=True), + sa.Column("topic2", sa.VARCHAR(length=256), nullable=True), + sa.Column("topic3", sa.VARCHAR(length=256), nullable=True), + sa.Column("log_index", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.ForeignKeyConstraint( + ["transaction_hash"], + ["game7_testnet_transactions.hash"], + name=op.f( + "fk_game7_testnet_logs_transaction_hash_game7_testnet_transactions" + ), + ondelete="CASCADE", + ), + sa.PrimaryKeyConstraint( + "transaction_hash", "log_index", name="pk_game7_testnet_log_index" + ), + sa.UniqueConstraint( + "transaction_hash", + "log_index", + name="uq_game7_testnet_log_index_transaction_hash_log_index", + ), + ) + op.create_index( + "idx_game7_testnet_logs_address_selector", + "game7_testnet_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_logs_address"), + "game7_testnet_logs", + ["address"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_logs_block_hash"), + "game7_testnet_logs", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_game7_testnet_logs_transaction_hash"), + "game7_testnet_logs", + ["transaction_hash"], + unique=False, + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + op.f("ix_game7_testnet_logs_transaction_hash"), table_name="game7_testnet_logs" + ) + op.drop_index( + op.f("ix_game7_testnet_logs_block_hash"), table_name="game7_testnet_logs" + ) + op.drop_index( + op.f("ix_game7_testnet_logs_address"), table_name="game7_testnet_logs" + ) + op.drop_index( + "idx_game7_testnet_logs_address_selector", table_name="game7_testnet_logs" + ) + op.drop_table("game7_testnet_logs") + op.drop_index( + op.f("ix_game7_testnet_transactions_type"), + table_name="game7_testnet_transactions", + ) + op.drop_index( + op.f("ix_game7_testnet_transactions_to_address"), + table_name="game7_testnet_transactions", + ) + op.drop_index( + op.f("ix_game7_testnet_transactions_selector"), + table_name="game7_testnet_transactions", + ) + op.drop_index( + op.f("ix_game7_testnet_transactions_index"), + table_name="game7_testnet_transactions", + ) + op.drop_index( + op.f("ix_game7_testnet_transactions_hash"), + table_name="game7_testnet_transactions", + ) + op.drop_index( + op.f("ix_game7_testnet_transactions_from_address"), + table_name="game7_testnet_transactions", + ) + op.drop_index( + op.f("ix_game7_testnet_transactions_block_number"), + table_name="game7_testnet_transactions", + ) + op.drop_index( + op.f("ix_game7_testnet_transactions_block_hash"), + table_name="game7_testnet_transactions", + ) + op.drop_table("game7_testnet_transactions") + op.drop_index( + op.f("ix_game7_testnet_reorgs_block_number"), table_name="game7_testnet_reorgs" + ) + op.drop_index( + op.f("ix_game7_testnet_reorgs_block_hash"), table_name="game7_testnet_reorgs" + ) + op.drop_table("game7_testnet_reorgs") + op.drop_index( + op.f("ix_game7_testnet_blocks_block_timestamp"), + table_name="game7_testnet_blocks", + ) + op.drop_index( + op.f("ix_game7_testnet_blocks_block_number"), table_name="game7_testnet_blocks" + ) + op.drop_table("game7_testnet_blocks") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/c1bc596631f9_add_game7_mainnet_indexes.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/c1bc596631f9_add_game7_mainnet_indexes.py new file mode 100644 index 0000000..3f111ba --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/c1bc596631f9_add_game7_mainnet_indexes.py @@ -0,0 +1,57 @@ +"""Add Game7 mainnet indexes + +Revision ID: c1bc596631f9 +Revises: 6807bdf6f417 +Create Date: 2024-10-14 16:10:27.757094 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'c1bc596631f9' +down_revision: Union[str, None] = '6807bdf6f417' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('game7_blocks', + sa.Column('l1_block_number', sa.BigInteger(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('transactions_indexed_at', sa.DateTime(timezone=True), nullable=True), + sa.Column('logs_indexed_at', sa.DateTime(timezone=True), nullable=True), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_game7_blocks')) + ) + op.create_index(op.f('ix_game7_blocks_block_number'), 'game7_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_game7_blocks_block_timestamp'), 'game7_blocks', ['block_timestamp'], unique=False) + op.create_table('game7_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_game7_reorgs')) + ) + op.create_index(op.f('ix_game7_reorgs_block_hash'), 'game7_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_game7_reorgs_block_number'), 'game7_reorgs', ['block_number'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_game7_reorgs_block_number'), table_name='game7_reorgs') + op.drop_index(op.f('ix_game7_reorgs_block_hash'), table_name='game7_reorgs') + op.drop_table('game7_reorgs') + op.drop_index(op.f('ix_game7_blocks_block_timestamp'), table_name='game7_blocks') + op.drop_index(op.f('ix_game7_blocks_block_number'), table_name='game7_blocks') + op.drop_table('game7_blocks') + # ### end Alembic commands ### \ No newline at end of file diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/e02c90ea67bb_logs_address_selector_index.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/e02c90ea67bb_logs_address_selector_index.py new file mode 100644 index 0000000..5e4928b --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/e02c90ea67bb_logs_address_selector_index.py @@ -0,0 +1,103 @@ +"""Logs address selector index + +Revision ID: e02c90ea67bb +Revises: a4ef4f9031e4 +Create Date: 2024-06-06 13:12:14.594600 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "e02c90ea67bb" +down_revision: Union[str, None] = "a4ef4f9031e4" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_index( + "idx_arbitrum_one_logs_address_selector", + "arbitrum_one_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_arbitrum_sepolia_logs_address_selector", + "arbitrum_sepolia_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_ethereum_logs_address_selector", + "ethereum_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_game7_orbit_arbitrum_sepolia_logs_address_selector", + "game7_orbit_arbitrum_sepolia_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_mantle_logs_address_selector", + "mantle_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_mantle_sepolia_logs_address_selector", + "mantle_sepolia_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_polygon_logs_address_selector", + "polygon_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_xai_logs_address_selector", + "xai_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_xai_sepolia_logs_address_selector", + "xai_sepolia_logs", + ["address", "selector"], + unique=False, + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + "idx_xai_sepolia_logs_address_selector", table_name="xai_sepolia_logs" + ) + op.drop_index("idx_xai_logs_address_selector", table_name="xai_logs") + op.drop_index("idx_polygon_logs_address_selector", table_name="polygon_logs") + op.drop_index( + "idx_mantle_sepolia_logs_address_selector", table_name="mantle_sepolia_logs" + ) + op.drop_index("idx_mantle_logs_address_selector", table_name="mantle_logs") + op.drop_index( + "idx_game7_orbit_arbitrum_sepolia_logs_address_selector", + table_name="game7_orbit_arbitrum_sepolia_logs", + ) + op.drop_index("idx_ethereum_logs_address_selector", table_name="ethereum_logs") + op.drop_index( + "idx_arbitrum_sepolia_logs_address_selector", table_name="arbitrum_sepolia_logs" + ) + op.drop_index( + "idx_arbitrum_one_logs_address_selector", table_name="arbitrum_one_logs" + ) + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f19652e59bc5_immutable_zkevm_with_it_s_sepolia_.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f19652e59bc5_immutable_zkevm_with_it_s_sepolia_.py new file mode 100644 index 0000000..3848860 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f19652e59bc5_immutable_zkevm_with_it_s_sepolia_.py @@ -0,0 +1,198 @@ +"""Immutable zkEvm with it's sepolia blockchains + +Revision ID: f19652e59bc5 +Revises: a1ead76c0470 +Create Date: 2024-07-25 11:34:09.513131 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'f19652e59bc5' +down_revision: Union[str, None] = 'a1ead76c0470' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('imx_zkevm_blocks', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_imx_zkevm_blocks')) + ) + op.create_index(op.f('ix_imx_zkevm_blocks_block_number'), 'imx_zkevm_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_blocks_block_timestamp'), 'imx_zkevm_blocks', ['block_timestamp'], unique=False) + op.create_table('imx_zkevm_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_imx_zkevm_reorgs')) + ) + op.create_index(op.f('ix_imx_zkevm_reorgs_block_hash'), 'imx_zkevm_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_reorgs_block_number'), 'imx_zkevm_reorgs', ['block_number'], unique=False) + op.create_table('imx_zkevm_sepolia_blocks', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_timestamp', sa.BigInteger(), nullable=False), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_imx_zkevm_sepolia_blocks')) + ) + op.create_index(op.f('ix_imx_zkevm_sepolia_blocks_block_number'), 'imx_zkevm_sepolia_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_blocks_block_timestamp'), 'imx_zkevm_sepolia_blocks', ['block_timestamp'], unique=False) + op.create_table('imx_zkevm_sepolia_reorgs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint('id', name=op.f('pk_imx_zkevm_sepolia_reorgs')) + ) + op.create_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_hash'), 'imx_zkevm_sepolia_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_number'), 'imx_zkevm_sepolia_reorgs', ['block_number'], unique=False) + op.create_table('imx_zkevm_sepolia_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['imx_zkevm_sepolia_blocks.block_number'], name=op.f('fk_imx_zkevm_sepolia_transactions_block_number_imx_zkevm_sepolia_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_imx_zkevm_sepolia_transactions')) + ) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_block_hash'), 'imx_zkevm_sepolia_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_block_number'), 'imx_zkevm_sepolia_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_from_address'), 'imx_zkevm_sepolia_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_hash'), 'imx_zkevm_sepolia_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_index'), 'imx_zkevm_sepolia_transactions', ['index'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_selector'), 'imx_zkevm_sepolia_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_to_address'), 'imx_zkevm_sepolia_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_type'), 'imx_zkevm_sepolia_transactions', ['type'], unique=False) + op.create_table('imx_zkevm_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['imx_zkevm_blocks.block_number'], name=op.f('fk_imx_zkevm_transactions_block_number_imx_zkevm_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_imx_zkevm_transactions')) + ) + op.create_index(op.f('ix_imx_zkevm_transactions_block_hash'), 'imx_zkevm_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_block_number'), 'imx_zkevm_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_from_address'), 'imx_zkevm_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_hash'), 'imx_zkevm_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_imx_zkevm_transactions_index'), 'imx_zkevm_transactions', ['index'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_selector'), 'imx_zkevm_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_to_address'), 'imx_zkevm_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_type'), 'imx_zkevm_transactions', ['type'], unique=False) + op.create_table('imx_zkevm_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic3', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['imx_zkevm_transactions.hash'], name=op.f('fk_imx_zkevm_logs_transaction_hash_imx_zkevm_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_imx_zkevm_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_imx_zkevm_log_index_transaction_hash_log_index') + ) + op.create_index('idx_imx_zkevm_logs_address_selector', 'imx_zkevm_logs', ['address', 'selector'], unique=False) + op.create_index('idx_imx_zkevm_logs_block_hash_log_index', 'imx_zkevm_logs', ['block_hash', 'log_index'], unique=True) + op.create_index(op.f('ix_imx_zkevm_logs_address'), 'imx_zkevm_logs', ['address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_logs_block_hash'), 'imx_zkevm_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_logs_transaction_hash'), 'imx_zkevm_logs', ['transaction_hash'], unique=False) + op.create_table('imx_zkevm_sepolia_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic3', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['imx_zkevm_sepolia_transactions.hash'], name=op.f('fk_imx_zkevm_sepolia_logs_transaction_hash_imx_zkevm_sepolia_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_imx_zkevm_sepolia_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_imx_zkevm_sepolia_log_index_transaction_hash_log_index') + ) + op.create_index('idx_imx_zkevm_sepolia_logs_address_selector', 'imx_zkevm_sepolia_logs', ['address', 'selector'], unique=False) + op.create_index('idx_imx_zkevm_sepolia_logs_block_hash_log_index', 'imx_zkevm_sepolia_logs', ['block_hash', 'log_index'], unique=True) + op.create_index(op.f('ix_imx_zkevm_sepolia_logs_address'), 'imx_zkevm_sepolia_logs', ['address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_logs_block_hash'), 'imx_zkevm_sepolia_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_logs_transaction_hash'), 'imx_zkevm_sepolia_logs', ['transaction_hash'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_imx_zkevm_sepolia_logs_transaction_hash'), table_name='imx_zkevm_sepolia_logs') + op.drop_index(op.f('ix_imx_zkevm_sepolia_logs_block_hash'), table_name='imx_zkevm_sepolia_logs') + op.drop_index(op.f('ix_imx_zkevm_sepolia_logs_address'), table_name='imx_zkevm_sepolia_logs') + op.drop_index('idx_imx_zkevm_sepolia_logs_block_hash_log_index', table_name='imx_zkevm_sepolia_logs') + op.drop_index('idx_imx_zkevm_sepolia_logs_address_selector', table_name='imx_zkevm_sepolia_logs') + op.drop_table('imx_zkevm_sepolia_logs') + op.drop_index(op.f('ix_imx_zkevm_logs_transaction_hash'), table_name='imx_zkevm_logs') + op.drop_index(op.f('ix_imx_zkevm_logs_block_hash'), table_name='imx_zkevm_logs') + op.drop_index(op.f('ix_imx_zkevm_logs_address'), table_name='imx_zkevm_logs') + op.drop_index('idx_imx_zkevm_logs_block_hash_log_index', table_name='imx_zkevm_logs') + op.drop_index('idx_imx_zkevm_logs_address_selector', table_name='imx_zkevm_logs') + op.drop_table('imx_zkevm_logs') + op.drop_index(op.f('ix_imx_zkevm_transactions_type'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_to_address'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_selector'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_index'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_hash'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_from_address'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_block_number'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_block_hash'), table_name='imx_zkevm_transactions') + op.drop_table('imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_type'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_to_address'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_selector'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_index'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_hash'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_from_address'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_block_number'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_block_hash'), table_name='imx_zkevm_sepolia_transactions') + op.drop_table('imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_number'), table_name='imx_zkevm_sepolia_reorgs') + op.drop_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_hash'), table_name='imx_zkevm_sepolia_reorgs') + op.drop_table('imx_zkevm_sepolia_reorgs') + op.drop_index(op.f('ix_imx_zkevm_sepolia_blocks_block_timestamp'), table_name='imx_zkevm_sepolia_blocks') + op.drop_index(op.f('ix_imx_zkevm_sepolia_blocks_block_number'), table_name='imx_zkevm_sepolia_blocks') + op.drop_table('imx_zkevm_sepolia_blocks') + op.drop_index(op.f('ix_imx_zkevm_reorgs_block_number'), table_name='imx_zkevm_reorgs') + op.drop_index(op.f('ix_imx_zkevm_reorgs_block_hash'), table_name='imx_zkevm_reorgs') + op.drop_table('imx_zkevm_reorgs') + op.drop_index(op.f('ix_imx_zkevm_blocks_block_timestamp'), table_name='imx_zkevm_blocks') + op.drop_index(op.f('ix_imx_zkevm_blocks_block_number'), table_name='imx_zkevm_blocks') + op.drop_table('imx_zkevm_blocks') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f2c6aa92e5d2_add_v3_subscription.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f2c6aa92e5d2_add_v3_subscription.py new file mode 100644 index 0000000..e1c9428 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f2c6aa92e5d2_add_v3_subscription.py @@ -0,0 +1,67 @@ +"""Add v3 subscription + +Revision ID: f2c6aa92e5d2 +Revises: 27086791044c +Create Date: 2024-07-11 19:41:49.899157 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "f2c6aa92e5d2" +down_revision: Union[str, None] = "27086791044c" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "abi_subscriptions", + sa.Column("abi_job_id", sa.UUID(), nullable=False), + sa.Column("subscription_id", sa.UUID(), nullable=False), + sa.Column( + "created_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.ForeignKeyConstraint( + ["abi_job_id"], + ["abi_jobs.id"], + name=op.f("fk_abi_subscriptions_abi_job_id_abi_jobs"), + ), + sa.PrimaryKeyConstraint( + "abi_job_id", "subscription_id", name=op.f("pk_abi_subscriptions") + ), + ) + op.create_index( + op.f("ix_abi_subscriptions_abi_job_id"), + "abi_subscriptions", + ["abi_job_id"], + unique=False, + ) + op.create_index( + op.f("ix_abi_subscriptions_subscription_id"), + "abi_subscriptions", + ["subscription_id"], + unique=False, + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + op.f("ix_abi_subscriptions_subscription_id"), table_name="abi_subscriptions" + ) + op.drop_index( + op.f("ix_abi_subscriptions_abi_job_id"), table_name="abi_subscriptions" + ) + op.drop_table("abi_subscriptions") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/blockchain.py b/moonstreamdb-v3/moonstreamdbv3/blockchain.py new file mode 100644 index 0000000..ecfaa52 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/blockchain.py @@ -0,0 +1,188 @@ +from enum import Enum +from typing import Type, Union + + +from .models import ( + EthereumLabel, + SepoliaLabel, + PolygonLabel, + MumbaiLabel, + AmoyLabel, + XDaiLabel, + ZkSyncEraLabel, + ZkSyncEraSepoliaLabel, + BaseLabel, + ArbitrumNovaLabel, + ArbitrumOneLabel, + ArbitrumSepoliaLabel, + Game7OrbitArbitrumSepoliaLabel, + Game7TestnetLabel, + XaiLabel, + XaiSepoliaLabel, + AvalancheLabel, + AvalancheFujiLabel, + BlastLabel, + BlastSepoliaLabel, + ProofOfPlayApexLabel, + StarknetLabel, + StarknetSepoliaLabel, + MantleLabel, + MantleSepoliaLabel, + B3Label, + B3SepoliaLabel, +) + + +class AvailableBlockchainType(Enum): + ETHEREUM = "ethereum" + POLYGON = "polygon" + MUMBAI = "mumbai" + AMOY = "amoy" + XDAI = "xdai" + SEPOLIA = "sepolia" + ZKSYNC_ERA = "zksync_era" + ZKSYNC_ERA_TESTNET = "zksync_era_testnet" + ZKSYNC_ERA_SEPOLIA = "zksync_era_sepolia" + ARBITRUM_ONE = "arbitrum_one" + ARBITRUM_NOVA = "arbitrum_nova" + ARBITRUM_SEPOLIA = "arbitrum_sepolia" + XAI = "xai" + XAI_SEPOLIA = "xai_sepolia" + AVALANCHE = "avalanche" + AVALANCHE_FUJI = "avalanche_fuji" + BLAST = "blast" + BLAST_SEPOLIA = "blast_sepolia" + PROOFOFPLAY_APEX = "proofofplay_apex" + STARKNET = "starknet" + STARKNET_SEPOLIA = "starknet_sepolia" + MANTLE = "mantle" + MANTLE_SEPOLIA = "mantle_sepolia" + GAME7_ORBIT_ARBITRUM_SEPOLIA = "game7_orbit_arbitrum_sepolia" + GAME7_TESTNET = "game7_testnet" + B3 = "b3" + B3_SEPOLIA = "b3_sepolia" + + +def get_label_model(blockchain_type: AvailableBlockchainType) -> Type[ + Union[ + EthereumLabel, + SepoliaLabel, + PolygonLabel, + MumbaiLabel, + AmoyLabel, + XDaiLabel, + ZkSyncEraLabel, + ZkSyncEraSepoliaLabel, + BaseLabel, + ArbitrumNovaLabel, + ArbitrumOneLabel, + ArbitrumSepoliaLabel, + Game7OrbitArbitrumSepoliaLabel, + Game7TestnetLabel, + XaiLabel, + XaiSepoliaLabel, + AvalancheLabel, + AvalancheFujiLabel, + BlastLabel, + BlastSepoliaLabel, + ProofOfPlayApexLabel, + StarknetLabel, + StarknetSepoliaLabel, + MantleLabel, + MantleSepoliaLabel, + B3Label, + B3SepoliaLabel, + ] +]: + """ + Depends on provided blockchain type set proper blocks model. + """ + + label_model: Type[ + Union[ + EthereumLabel, + SepoliaLabel, + PolygonLabel, + MumbaiLabel, + AmoyLabel, + XDaiLabel, + ZkSyncEraLabel, + ZkSyncEraSepoliaLabel, + BaseLabel, + ArbitrumNovaLabel, + ArbitrumOneLabel, + ArbitrumSepoliaLabel, + Game7OrbitArbitrumSepoliaLabel, + Game7TestnetLabel, + XaiLabel, + XaiSepoliaLabel, + AvalancheLabel, + AvalancheFujiLabel, + BlastLabel, + BlastSepoliaLabel, + ProofOfPlayApexLabel, + StarknetLabel, + StarknetSepoliaLabel, + MantleLabel, + MantleSepoliaLabel, + B3Label, + B3SepoliaLabel, + ] + ] + + if blockchain_type == AvailableBlockchainType.ETHEREUM: + label_model = EthereumLabel + elif blockchain_type == AvailableBlockchainType.SEPOLIA: + label_model = SepoliaLabel + elif blockchain_type == AvailableBlockchainType.POLYGON: + label_model = PolygonLabel + elif blockchain_type == AvailableBlockchainType.MUMBAI: + label_model = MumbaiLabel + elif blockchain_type == AvailableBlockchainType.AMOY: + label_model = AmoyLabel + elif blockchain_type == AvailableBlockchainType.XDAI: + label_model = XDaiLabel + elif blockchain_type == AvailableBlockchainType.ZKSYNC_ERA: + label_model = ZkSyncEraLabel + elif blockchain_type == AvailableBlockchainType.ZKSYNC_ERA_SEPOLIA: + label_model = ZkSyncEraSepoliaLabel + elif blockchain_type == AvailableBlockchainType.ARBITRUM_ONE: + label_model = ArbitrumOneLabel + elif blockchain_type == AvailableBlockchainType.ARBITRUM_NOVA: + label_model = ArbitrumNovaLabel + elif blockchain_type == AvailableBlockchainType.ARBITRUM_SEPOLIA: + label_model = ArbitrumSepoliaLabel + elif blockchain_type == AvailableBlockchainType.XAI: + label_model = XaiLabel + elif blockchain_type == AvailableBlockchainType.XAI_SEPOLIA: + label_model = XaiSepoliaLabel + elif blockchain_type == AvailableBlockchainType.AVALANCHE: + label_model = AvalancheLabel + elif blockchain_type == AvailableBlockchainType.AVALANCHE_FUJI: + label_model = AvalancheFujiLabel + elif blockchain_type == AvailableBlockchainType.BLAST: + label_model = BlastLabel + elif blockchain_type == AvailableBlockchainType.BLAST_SEPOLIA: + label_model = BlastSepoliaLabel + elif blockchain_type == AvailableBlockchainType.PROOFOFPLAY_APEX: + label_model = ProofOfPlayApexLabel + elif blockchain_type == AvailableBlockchainType.STARKNET: + label_model = StarknetLabel + elif blockchain_type == AvailableBlockchainType.STARKNET_SEPOLIA: + label_model = StarknetSepoliaLabel + elif blockchain_type == AvailableBlockchainType.MANTLE: + label_model = MantleLabel + elif blockchain_type == AvailableBlockchainType.MANTLE_SEPOLIA: + label_model = MantleSepoliaLabel + elif blockchain_type == AvailableBlockchainType.GAME7_ORBIT_ARBITRUM_SEPOLIA: + label_model = Game7OrbitArbitrumSepoliaLabel + elif blockchain_type == AvailableBlockchainType.GAME7_TESTNET: + label_model = Game7TestnetLabel + elif blockchain_type == AvailableBlockchainType.B3: + label_model = B3Label + elif blockchain_type == AvailableBlockchainType.B3_SEPOLIA: + label_model = B3SepoliaLabel + else: + raise ValueError(f"Unknown blockchain type: {blockchain_type}") + + return label_model diff --git a/moonstreamdb-v3/moonstreamdbv3/db.py b/moonstreamdb-v3/moonstreamdbv3/db.py new file mode 100644 index 0000000..14a1e02 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/db.py @@ -0,0 +1,262 @@ +""" +Moonstream database connection. +""" + +import logging +import os +from contextlib import contextmanager +from typing import Generator, Optional + +from sqlalchemy import Engine, create_engine +from sqlalchemy.orm import Session, sessionmaker + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +MOONSTREAM_DB_V3_URI = os.environ.get("MOONSTREAM_DB_V3_URI") +if MOONSTREAM_DB_V3_URI is None: + logger.warning("MOONSTREAM_DB_V3_URI environment variable must be set") + +MOONSTREAM_DB_V3_URI_READ_ONLY = os.environ.get("MOONSTREAM_DB_V3_URI_READ_ONLY") +if MOONSTREAM_DB_V3_URI_READ_ONLY is None: + logger.warning("MOONSTREAM_DB_V3_URI_READ_ONLY environment variable must be set") + +try: + MOONSTREAM_DB_V3_INDEXES_URI = os.environ.get("MOONSTREAM_DB_V3_INDEXES_URI") + if MOONSTREAM_DB_V3_INDEXES_URI is None: + raise Warning("MOONSTREAM_DB_V3_INDEXES_URI environment variable must be set") + + MOONSTREAM_DB_V3_INDEXES_URI_READ_ONLY = os.environ.get( + "MOONSTREAM_DB_V3_INDEXES_URI_READ_ONLY" + ) + if MOONSTREAM_DB_V3_INDEXES_URI_READ_ONLY is None: + raise Warning( + "MOONSTREAM_DB_V3_INDEXES_URI_READ_ONLY environment variable must be set" + ) +except ValueError as e: + raise ValueError(e) +except Warning: + logger.warning("Indexes database variables not set") + +MOONSTREAM_POOL_SIZE_RAW = os.environ.get("MOONSTREAM_POOL_SIZE") +MOONSTREAM_POOL_SIZE = 1 +try: + if MOONSTREAM_POOL_SIZE_RAW is not None: + MOONSTREAM_POOL_SIZE = int(MOONSTREAM_POOL_SIZE_RAW) +except: + raise ValueError( + f"Could not parse MOONSTREAM_POOL_SIZE as int: {MOONSTREAM_POOL_SIZE_RAW}" + ) + +MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW = os.environ.get( + "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS" +) +MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS = 30000 +try: + if MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW is not None: + MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS = int( + MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW + ) +except: + raise ValueError( + f"MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS must be an integer: {MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW}" + ) + + +def create_moonstream_engine( + url: str, + pool_size: int, + statement_timeout: int, + pool_pre_ping: bool = False, + schema: Optional[str] = None, +) -> Engine: + # Pooling: https://docs.sqlalchemy.org/en/14/core/pooling.html#sqlalchemy.pool.QueuePool + # Statement timeout: https://stackoverflow.com/a/44936982 + options = f"-c statement_timeout={statement_timeout}" + if schema is not None: + options += f" -c search_path={schema}" + return create_engine( + url=url, + pool_pre_ping=pool_pre_ping, + pool_size=pool_size, + connect_args={"options": options}, + ) + + +class DBEngine: + def __init__(self, url: str, schema: Optional[str] = None) -> None: + self._engine = create_moonstream_engine( + url=url, # type: ignore + pool_size=MOONSTREAM_POOL_SIZE, + statement_timeout=MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS, + schema=schema, + ) + + @property + def engine(self) -> Engine: + return self._engine + + +class MoonstreamDBEngine(DBEngine): + def __init__(self, schema: Optional[str] = None) -> None: + super().__init__(url=MOONSTREAM_DB_V3_URI, schema=schema) + + self._session_local = sessionmaker(bind=self.engine) + + self._yield_db_session_ctx = contextmanager(self.yield_db_session) + + @property + def session_local(self): + return self._session_local + + @property + def yield_db_session_ctx(self): + return self._yield_db_session_ctx + + def yield_db_session( + self, + ) -> Generator[Session, None, None]: + """ + Yields a database connection (created using environment variables). + As per FastAPI docs: + https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency + """ + session = self._session_local() + try: + yield session + finally: + session.close() + + +class MoonstreamDBEngineRO(DBEngine): + def __init__(self, schema: Optional[str] = None) -> None: + super().__init__(url=MOONSTREAM_DB_V3_URI_READ_ONLY, schema=schema) + + @property + def engine(self): + raise AttributeError( + "RO_engine should be used instead of engine for read-only access." + ) + + @property + def RO_engine(self) -> Engine: + return self._engine + + @property + def RO_session_local(self): + return self._session_local + + @property + def RO_yield_db_session_ctx(self): + return self._yield_db_session_ctx + + def yield_db_read_only_session(self) -> Generator[Session, None, None]: + """ + Yields read-only database connection (created using environment variables). + As per FastAPI docs: + https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency + """ + session = self._session_local() + try: + yield session + finally: + session.close() + + +class MoonstreamCustomDBEngine(DBEngine): + def __init__(self, url: str, schema: Optional[str] = None) -> None: + super().__init__(url=url, schema=schema) + + logger.warning("Initialized custom database engine with specified URI") + + self._session_local = sessionmaker(bind=self.engine) + + self._yield_db_session_ctx = contextmanager(self.yield_db_session) + + @property + def session_local(self): + return self._session_local + + @property + def yield_db_session_ctx(self): + return self._yield_db_session_ctx + + def yield_db_session( + self, + ) -> Generator[Session, None, None]: + """ + Yields a database connection (created using environment variables). + As per FastAPI docs: + https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency + """ + session = self._session_local() + try: + yield session + finally: + session.close() + + +class MoonstreamDBIndexesEngine(DBEngine): + def __init__(self, schema: Optional[str] = None) -> None: + super().__init__(url=MOONSTREAM_DB_V3_INDEXES_URI, schema=schema) + + self._session_local = sessionmaker(bind=self.engine) + + self._yield_db_session_ctx = contextmanager(self.yield_db_session) + + @property + def session_local(self): + return self._session_local + + @property + def yield_db_session_ctx(self): + return self._yield_db_session_ctx + + def yield_db_session( + self, + ) -> Generator[Session, None, None]: + """ + Yields a database connection (created using environment variables). + As per FastAPI docs: + https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency + """ + session = self._session_local() + try: + yield session + finally: + session.close() + + +class MoonstreamDBIndexesEngineRO(DBEngine): + def __init__(self, schema: Optional[str] = None) -> None: + super().__init__(url=MOONSTREAM_DB_V3_INDEXES_URI_READ_ONLY, schema=schema) + + @property + def engine(self): + raise AttributeError( + "RO_engine should be used instead of engine for read-only access." + ) + + @property + def RO_engine(self) -> Engine: + return self._engine + + @property + def RO_session_local(self): + return self._session_local + + @property + def RO_yield_db_session_ctx(self): + return self._yield_db_session_ctx + + def yield_db_read_only_session(self) -> Generator[Session, None, None]: + """ + Yields read-only database connection (created using environment variables). + As per FastAPI docs: + https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency + """ + session = self._session_local() + try: + yield session + finally: + session.close() diff --git a/moonstreamdb-v3/moonstreamdbv3/models/__init__.py b/moonstreamdb-v3/moonstreamdbv3/models/__init__.py new file mode 100644 index 0000000..7458806 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/__init__.py @@ -0,0 +1,27 @@ +from .ethereum_labels import EthereumLabel +from .sepolia_labels import SepoliaLabel +from .polygon_labels import PolygonLabel +from .mumbai_labels import MumbaiLabel +from .amoy_labels import AmoyLabel +from .xdai_labels import XDaiLabel +from .zksync_era_labels import ZksyncEraLabel +from .zksync_era_sepolia_labels import ZksyncEraSepoliaLabel +from .base_labels import BaseLabel +from .arbitrum_nova_labels import ArbitrumNovaLabel +from .arbitrum_one_labels import ArbitrumOneLabel +from .arbitrum_sepolia_labels import ArbitrumSepoliaLabel +from .game7_orbit_arbitrum_sepolia_labels import Game7OrbitArbitrumSepoliaLabel +from .game7_testnet_labels import Game7TestnetLabel +from .xai_labels import XaiLabel +from .xai_sepolia_labels import XaiSepoliaLabel +from .avalanche_labels import AvalancheLabel +from .avalanche_fuji_labels import AvalancheFujiLabel +from .blast_labels import BlastLabel +from .blast_sepolia_labels import BlastSepoliaLabel +from .proofofplay_apex_labels import ProofOfPlayApexLabel +from .starknet_labels import StarknetLabel +from .starknet_sepolia_labels import StarknetSepoliaLabel +from .mantle_labels import MantleLabel +from .mantle_sepolia_labels import MantleSepoliaLabel +from .b3_labels import B3Label +from .b3_sepolia_labels import B3SepoliaLabel diff --git a/moonstreamdb-v3/moonstreamdbv3/models/abstract_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/abstract_labels.py new file mode 100644 index 0000000..82b2895 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/abstract_labels.py @@ -0,0 +1,119 @@ +""" +Moonstream database V3 + +Example of label_data column record: + { + "label": "ERC20", + "label_data": { + "name": "Uniswap", + "symbol": "UNI" + } + }, + { + "label": "Exchange" + "label_data": {...} + } +""" + +import uuid + +from sqlalchemy import ( + VARCHAR, + BigInteger, + Column, + DateTime, + Index, + Integer, + LargeBinary, + MetaData, + Text, +) +from sqlalchemy.dialects.postgresql import JSONB, UUID +from sqlalchemy.ext.compiler import compiles +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.sql import expression, text + +""" +Naming conventions doc +https://docs.sqlalchemy.org/en/20/core/constraints.html#configuring-constraint-naming-conventions +""" +convention = { + "ix": "ix_%(column_0_label)s", + "uq": "uq_%(table_name)s_%(column_0_name)s", + "ck": "ck_%(table_name)s_%(constraint_name)s", + "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", + "pk": "pk_%(table_name)s", +} +metadata = MetaData(naming_convention=convention) +Base = declarative_base(metadata=metadata) + +""" +Creating a utcnow function which runs on the Posgres database server when created_at and updated_at +fields are populated. +Following: +1. https://docs.sqlalchemy.org/en/13/core/compiler.html#utc-timestamp-function +2. https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT +3. https://stackoverflow.com/a/33532154/13659585 +""" + + +class utcnow(expression.FunctionElement): + type = DateTime # type: ignore + + +@compiles(utcnow, "postgresql") +def pg_utcnow(element, compiler, **kwargs): + return "TIMEZONE('utc', statement_timestamp())" + + +class EvmBasedLabel(Base): # type: ignore + __abstract__ = True + + id = Column( + UUID(as_uuid=True), + primary_key=True, + default=uuid.uuid4, + unique=True, + nullable=False, + ) + label = Column(VARCHAR(256), nullable=False, index=True) + + transaction_hash = Column( + VARCHAR(128), + nullable=False, + index=True, + ) + log_index = Column(Integer, nullable=True) + + block_number = Column( + BigInteger, + nullable=False, + index=True, + ) + block_hash = Column(VARCHAR(256), nullable=False) + block_timestamp = Column(BigInteger, nullable=False) + + caller_address = Column( + LargeBinary, + nullable=True, + index=True, + ) + origin_address = Column( + LargeBinary, + nullable=True, + index=True, + ) + + address = Column( + LargeBinary, + nullable=False, + index=True, + ) + + label_name = Column(Text, nullable=True, index=True) + label_type = Column(VARCHAR(64), nullable=True, index=True) + label_data = Column(JSONB, nullable=True) + + created_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/amoy_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/amoy_labels.py new file mode 100644 index 0000000..0df1d13 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/amoy_labels.py @@ -0,0 +1,49 @@ +# amoy_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class AmoyLabel(EvmBasedLabel): + __tablename__ = "amoy_labels" + + __table_args__ = ( + Index( + "ix_amoy_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_amoy_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_amoy_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_amoy_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_amoy_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_amoy_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/arbitrum_nova_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/arbitrum_nova_labels.py new file mode 100644 index 0000000..eb03ab2 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/arbitrum_nova_labels.py @@ -0,0 +1,49 @@ +# arbitrum_nova_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class ArbitrumNovaLabel(EvmBasedLabel): + __tablename__ = "arbitrum_nova_labels" + + __table_args__ = ( + Index( + "ix_arbitrum_nova_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_arbitrum_nova_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_arbitrum_nova_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_arbitrum_nova_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_arbitrum_nova_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_arbitrum_nova_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/arbitrum_one_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/arbitrum_one_labels.py new file mode 100644 index 0000000..9c0c7f2 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/arbitrum_one_labels.py @@ -0,0 +1,49 @@ +# arbitrum_one_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class ArbitrumOneLabel(EvmBasedLabel): + __tablename__ = "arbitrum_one_labels" + + __table_args__ = ( + Index( + "ix_arbitrum_one_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_arbitrum_one_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_arbitrum_one_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_arbitrum_one_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_arbitrum_one_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_arbitrum_one_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/arbitrum_sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/arbitrum_sepolia_labels.py new file mode 100644 index 0000000..b28e4a8 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/arbitrum_sepolia_labels.py @@ -0,0 +1,49 @@ +# arbitrum_sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class ArbitrumSepoliaLabel(EvmBasedLabel): + __tablename__ = "arbitrum_sepolia_labels" + + __table_args__ = ( + Index( + "ix_arbitrum_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_arbitrum_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_arbitrum_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_arbitrum_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_arbitrum_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_arbitrum_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/avalanche_fuji_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/avalanche_fuji_labels.py new file mode 100644 index 0000000..5c8fea4 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/avalanche_fuji_labels.py @@ -0,0 +1,49 @@ +# avalanche_fuji_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class AvalancheFujiLabel(EvmBasedLabel): + __tablename__ = "avalanche_fuji_labels" + + __table_args__ = ( + Index( + "ix_avalanche_fuji_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_avalanche_fuji_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_avalanche_fuji_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_avalanche_fuji_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_avalanche_fuji_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_avalanche_fuji_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/avalanche_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/avalanche_labels.py new file mode 100644 index 0000000..2342a01 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/avalanche_labels.py @@ -0,0 +1,49 @@ +# avalanche_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class AvalancheLabel(EvmBasedLabel): + __tablename__ = "avalanche_labels" + + __table_args__ = ( + Index( + "ix_avalanche_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_avalanche_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_avalanche_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_avalanche_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_avalanche_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_avalanche_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/b3_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/b3_labels.py new file mode 100644 index 0000000..d8add00 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/b3_labels.py @@ -0,0 +1,49 @@ +# b3_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class B3Label(EvmBasedLabel): + __tablename__ = "b3_labels" + + __table_args__ = ( + Index( + "ix_b3_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_b3_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_b3_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_b3_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_b3_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_b3_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/b3_sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/b3_sepolia_labels.py new file mode 100644 index 0000000..0df6542 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/b3_sepolia_labels.py @@ -0,0 +1,49 @@ +# b3_sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class B3SepoliaLabel(EvmBasedLabel): + __tablename__ = "b3_sepolia_labels" + + __table_args__ = ( + Index( + "ix_b3_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_b3_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_b3_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_b3_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/base_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/base_labels.py new file mode 100644 index 0000000..6ea83d6 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/base_labels.py @@ -0,0 +1,49 @@ +# base_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class BaseLabel(EvmBasedLabel): + __tablename__ = "base_labels" + + __table_args__ = ( + Index( + "ix_base_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_base_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_base_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_base_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_base_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_base_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/blast_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/blast_labels.py new file mode 100644 index 0000000..b960683 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/blast_labels.py @@ -0,0 +1,49 @@ +# blast_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class BlastLabel(EvmBasedLabel): + __tablename__ = "blast_labels" + + __table_args__ = ( + Index( + "ix_blast_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_blast_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_blast_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_blast_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_blast_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_blast_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/blast_sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/blast_sepolia_labels.py new file mode 100644 index 0000000..c205deb --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/blast_sepolia_labels.py @@ -0,0 +1,49 @@ +# blast_sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class BlastSepoliaLabel(EvmBasedLabel): + __tablename__ = "blast_sepolia_labels" + + __table_args__ = ( + Index( + "ix_blast_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_blast_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_blast_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_blast_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_blast_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_blast_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/ethereum_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/ethereum_labels.py new file mode 100644 index 0000000..3609507 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/ethereum_labels.py @@ -0,0 +1,49 @@ +# ethereum_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class EthereumLabel(EvmBasedLabel): + __tablename__ = "ethereum_labels" + + __table_args__ = ( + Index( + "ix_ethereum_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_ethereum_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_ethereum_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_ethereum_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_ethereum_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_ethereum_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/game7_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/game7_labels.py new file mode 100644 index 0000000..dbac074 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/game7_labels.py @@ -0,0 +1,49 @@ +# game7_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class Game7Label(EvmBasedLabel): # type: ignore + __tablename__ = "game7_labels" + + __table_args__ = ( + Index( + "ix_game7_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_game7_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_game7_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_game7_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_game7_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_game7_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/game7_orbit_arbitrum_sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/game7_orbit_arbitrum_sepolia_labels.py new file mode 100644 index 0000000..2d3bae1 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/game7_orbit_arbitrum_sepolia_labels.py @@ -0,0 +1,49 @@ +# game7_orbit_arbitrum_sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class Game7OrbitArbitrumSepoliaLabel(EvmBasedLabel): + __tablename__ = "game7_orbit_arbitrum_sepolia_labels" + + __table_args__ = ( + Index( + "ix_game7_orbit_arbitrum_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_game7_orbit_arbitrum_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_game7_orbit_arbitrum_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_game7_orbit_arbitrum_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_game7_orbit_arbitrum_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_game7_orbit_arbitrum_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/game7_testnet_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/game7_testnet_labels.py new file mode 100644 index 0000000..63f9240 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/game7_testnet_labels.py @@ -0,0 +1,49 @@ +# game7_testnet_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class Game7TestnetLabel(EvmBasedLabel): + __tablename__ = "game7_testnet_labels" + + __table_args__ = ( + Index( + "ix_game7_testnet_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_game7_testnet_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_game7_testnet_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_game7_testnet_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_game7_testnet_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_game7_testnet_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/imx_zkevm_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/imx_zkevm_labels.py new file mode 100644 index 0000000..f483ca4 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/imx_zkevm_labels.py @@ -0,0 +1,48 @@ +# imx_zkevm_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + +class ImxZkevmlabel(EvmBasedLabel): + __tablename__ = "imx_zkevm_labels" + + __table_args__ = ( + Index( + "ix_imx_zkevm_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_imx_zkevm_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_imx_zkevm_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_imx_zkevm_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_imx_zkevm_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_imx_zkevm_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) \ No newline at end of file diff --git a/moonstreamdb-v3/moonstreamdbv3/models/imx_zkevm_sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/imx_zkevm_sepolia_labels.py new file mode 100644 index 0000000..c9dd78c --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/imx_zkevm_sepolia_labels.py @@ -0,0 +1,48 @@ +# imx_zkevm_sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + +class ImxZkevmSepolialabel(EvmBasedLabel): + __tablename__ = "imx_zkevm_sepolia_labels" + + __table_args__ = ( + Index( + "ix_imx_zkevm_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_imx_zkevm_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_imx_zkevm_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_imx_zkevm_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) \ No newline at end of file diff --git a/moonstreamdb-v3/moonstreamdbv3/models/mantle_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/mantle_labels.py new file mode 100644 index 0000000..f8343df --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/mantle_labels.py @@ -0,0 +1,49 @@ +# mantle_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class MantleLabel(EvmBasedLabel): + __tablename__ = "mantle_labels" + + __table_args__ = ( + Index( + "ix_mantle_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_mantle_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_mantle_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_mantle_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_mantle_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_mantle_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/mantle_sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/mantle_sepolia_labels.py new file mode 100644 index 0000000..c161370 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/mantle_sepolia_labels.py @@ -0,0 +1,49 @@ +# mantle_sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class MantleSepoliaLabel(EvmBasedLabel): + __tablename__ = "mantle_sepolia_labels" + + __table_args__ = ( + Index( + "ix_mantle_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_mantle_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_mantle_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_mantle_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_mantle_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_mantle_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/mumbai_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/mumbai_labels.py new file mode 100644 index 0000000..2648afd --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/mumbai_labels.py @@ -0,0 +1,49 @@ +# mumbai_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class MumbaiLabel(EvmBasedLabel): + __tablename__ = "mumbai_labels" + + __table_args__ = ( + Index( + "ix_mumbai_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_mumbai_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_mumbai_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_mumbai_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_mumbai_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_mumbai_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/polygon_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/polygon_labels.py new file mode 100644 index 0000000..48bda56 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/polygon_labels.py @@ -0,0 +1,49 @@ +# polygon_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class PolygonLabel(EvmBasedLabel): + __tablename__ = "polygon_labels" + + __table_args__ = ( + Index( + "ix_polygon_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_polygon_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_polygon_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_polygon_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_polygon_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_polygon_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/proofofplay_apex_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/proofofplay_apex_labels.py new file mode 100644 index 0000000..03d8172 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/proofofplay_apex_labels.py @@ -0,0 +1,49 @@ +# proofofplay_apex_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class ProofOfPlayApexLabel(EvmBasedLabel): + __tablename__ = "proofofplay_apex_labels" + + __table_args__ = ( + Index( + "ix_proofofplay_apex_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_proofofplay_apex_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_proofofplay_apex_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_proofofplay_apex_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_proofofplay_apex_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_proofofplay_apex_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/sepolia_labels.py new file mode 100644 index 0000000..2ca046f --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/sepolia_labels.py @@ -0,0 +1,49 @@ +# sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class SepoliaLabel(EvmBasedLabel): + __tablename__ = "sepolia_labels" + + __table_args__ = ( + Index( + "ix_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/starknet_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/starknet_labels.py new file mode 100644 index 0000000..3751422 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/starknet_labels.py @@ -0,0 +1,49 @@ +# starknet_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class StarknetLabel(EvmBasedLabel): + __tablename__ = "starknet_labels" + + __table_args__ = ( + Index( + "ix_starknet_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_starknet_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_starknet_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_starknet_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_starknet_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_starknet_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/starknet_sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/starknet_sepolia_labels.py new file mode 100644 index 0000000..6716358 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/starknet_sepolia_labels.py @@ -0,0 +1,49 @@ +# starknet_sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class StarknetSepoliaLabel(EvmBasedLabel): + __tablename__ = "starknet_sepolia_labels" + + __table_args__ = ( + Index( + "ix_starknet_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_starknet_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_starknet_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_starknet_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_starknet_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_starknet_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/xai_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/xai_labels.py new file mode 100644 index 0000000..ce21fd1 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/xai_labels.py @@ -0,0 +1,49 @@ +# xai_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class XaiLabel(EvmBasedLabel): + __tablename__ = "xai_labels" + + __table_args__ = ( + Index( + "ix_xai_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_xai_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_xai_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_xai_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_xai_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_xai_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/xai_sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/xai_sepolia_labels.py new file mode 100644 index 0000000..4190877 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/xai_sepolia_labels.py @@ -0,0 +1,49 @@ +# xai_sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class XaiSepoliaLabel(EvmBasedLabel): + __tablename__ = "xai_sepolia_labels" + + __table_args__ = ( + Index( + "ix_xai_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_xai_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_xai_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_xai_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_xai_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_xai_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/xdai_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/xdai_labels.py new file mode 100644 index 0000000..991fc5e --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/xdai_labels.py @@ -0,0 +1,49 @@ +# xdai_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class XDaiLabel(EvmBasedLabel): + __tablename__ = "xdai_labels" + + __table_args__ = ( + Index( + "ix_xdai_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_xdai_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_xdai_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_xdai_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_xdai_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_xdai_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/zksync_era_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/zksync_era_labels.py new file mode 100644 index 0000000..9f0b99c --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/zksync_era_labels.py @@ -0,0 +1,49 @@ +# zksync_era_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class ZksyncEraLabel(EvmBasedLabel): + __tablename__ = "zksync_era_labels" + + __table_args__ = ( + Index( + "ix_zksync_era_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_zksync_era_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_zksync_era_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_zksync_era_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_zksync_era_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_zksync_era_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models/zksync_era_sepolia_labels.py b/moonstreamdb-v3/moonstreamdbv3/models/zksync_era_sepolia_labels.py new file mode 100644 index 0000000..ec79425 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models/zksync_era_sepolia_labels.py @@ -0,0 +1,49 @@ +# zksync_era_sepolia_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + + +class ZksyncEraSepoliaLabel(EvmBasedLabel): + __tablename__ = "zksync_era_sepolia_labels" + + __table_args__ = ( + Index( + "ix_zksync_era_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_zksync_era_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_zksync_era_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_zksync_era_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_zksync_era_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_zksync_era_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py.tmpl b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py.tmpl new file mode 100644 index 0000000..fe2b2ba --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py.tmpl @@ -0,0 +1,14 @@ +# {{ .BlockchainNameLower }}_indexes.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class {{ .BlockchainName }}BlockIndex(EvmBasedBlocks): + __tablename__ = "{{ .BlockchainNameLower }}_blocks" + + {{- if .IsSideChain }} + l1_block_number = Column(BigInteger, nullable=False) + {{- end }} + +class {{ .BlockchainName }}Reorgs(EvmBasedReorgs): + __tablename__ = "{{ .BlockchainNameLower }}_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/__init__.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/abstract_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/abstract_indexes.py new file mode 100644 index 0000000..0aa7f5a --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/abstract_indexes.py @@ -0,0 +1,154 @@ +import uuid + +from sqlalchemy import ( + VARCHAR, + BigInteger, + Boolean, + Column, + DateTime, + ForeignKey, + Index, + Integer, + LargeBinary, + MetaData, + PrimaryKeyConstraint, + Text, + UniqueConstraint, +) +from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy.ext.compiler import compiles +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.sql import expression + +""" +Naming conventions doc +https://docs.sqlalchemy.org/en/13/core/constraints.html#configuring-constraint-naming-conventions +""" +convention = { + "ix": "ix_%(column_0_label)s", + "uq": "uq_%(table_name)s_%(column_0_name)s", + "ck": "ck_%(table_name)s_%(constraint_name)s", + "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", + "pk": "pk_%(table_name)s", +} +metadata = MetaData(naming_convention=convention) +Base = declarative_base(metadata=metadata) + + +class utcnow(expression.FunctionElement): + type = DateTime # type: ignore + + +@compiles(utcnow, "postgresql") +def pg_utcnow(element, compiler, **kwargs): + return "TIMEZONE('utc', statement_timestamp())" + + +class EvmBasedBlocks(Base): + __abstract__ = True + + block_number = Column(BigInteger, primary_key=True, nullable=False, index=True) + block_hash = Column(VARCHAR(256), nullable=False, index=False) + block_timestamp = Column(BigInteger, nullable=False, index=True) + parent_hash = Column(VARCHAR(256), nullable=False) + row_id = Column(BigInteger, nullable=False, index=False) + path = Column(Text, nullable=False) + transactions_indexed_at = Column(DateTime(timezone=True), nullable=True) + logs_indexed_at = Column(DateTime(timezone=True), nullable=True) + indexed_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + +class EvmBasedTransactions(Base): + __abstract__ = True + + hash = Column( + VARCHAR(256), primary_key=True, unique=True, nullable=False, index=True + ) + from_address = Column(LargeBinary(length=20), nullable=False, index=True) + to_address = Column(LargeBinary(length=20), nullable=False, index=True) + selector = Column(VARCHAR(256), nullable=True, index=True) + type = Column(Integer, nullable=True, index=True) + row_id = Column(BigInteger, nullable=False, index=False) + block_hash = Column(VARCHAR(256), nullable=False, index=True) + index = Column(BigInteger, nullable=False, index=True) + path = Column(Text, nullable=False) + indexed_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + +class EvmBasedLogs(Base): + __abstract__ = True + + block_hash = Column(VARCHAR(256), nullable=False, index=True) + address = Column(LargeBinary(length=20), nullable=False, index=True) + row_id = Column(BigInteger, nullable=False, index=False) + selector = Column(VARCHAR(256), nullable=True, index=False) + topic1 = Column(VARCHAR(256), nullable=True, index=False) + topic2 = Column(VARCHAR(256), nullable=True, index=False) + topic3 = Column(VARCHAR(256), nullable=True, index=False) + log_index = Column(BigInteger, nullable=False, index=False) + path = Column(Text, nullable=False) + indexed_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + +class EvmBasedReorgs(Base): + __abstract__ = True + id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) + block_number = Column(BigInteger, nullable=False, index=True) + block_hash = Column(VARCHAR(256), nullable=False, index=True) + + +class AbiJobs(Base): + __tablename__ = "abi_jobs" + + __table_args__ = ( + UniqueConstraint( + "chain", + "address", + "abi_selector", + "customer_id", + name="uq_abi_jobs", + ), + ) + + id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) + address = Column(LargeBinary, nullable=False, index=True) + user_id = Column(UUID(as_uuid=True), nullable=False, index=True) + customer_id = Column(UUID(as_uuid=True), nullable=True, index=True) + abi_selector = Column(VARCHAR(256), nullable=False, index=True) + chain = Column(VARCHAR(256), nullable=False, index=True) + abi_name = Column(VARCHAR(256), nullable=False, index=True) + status = Column(VARCHAR(256), nullable=False, index=True) + historical_crawl_status = Column(VARCHAR(256), nullable=False, index=True) + progress = Column(Integer, nullable=False, index=False) + moonworm_task_pickedup = Column(Boolean, nullable=False, index=False) + deployment_block_number = Column(BigInteger, nullable=True, index=False) + abi = Column(Text, nullable=False) + created_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + updated_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + +class AbiSubscriptions(Base): + __tablename__ = "abi_subscriptions" + + __table_args__ = (PrimaryKeyConstraint("abi_job_id", "subscription_id"),) + + abi_job_id = Column( + UUID(as_uuid=True), + ForeignKey("abi_jobs.id"), + nullable=False, + index=True, + ) + subscription_id = Column(UUID(as_uuid=True), nullable=False, index=True) + created_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/arbitrum_one_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/arbitrum_one_indexes.py new file mode 100644 index 0000000..8b98670 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/arbitrum_one_indexes.py @@ -0,0 +1,11 @@ +# arbitrum_one_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class ArbitrumOneBlockIndex(EvmBasedBlocks): + __tablename__ = "arbitrum_one_blocks" + l1_block_number = Column(BigInteger, nullable=False) + +class ArbitrumOneReorgs(EvmBasedReorgs): + __tablename__ = "arbitrum_one_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/arbitrum_sepolia_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/arbitrum_sepolia_indexes.py new file mode 100644 index 0000000..f13fc6d --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/arbitrum_sepolia_indexes.py @@ -0,0 +1,11 @@ +# arbitrum_sepolia_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class ArbitrumSepoliaBlockIndex(EvmBasedBlocks): + __tablename__ = "arbitrum_sepolia_blocks" + l1_block_number = Column(BigInteger, nullable=False) + +class ArbitrumSepoliaReorgs(EvmBasedReorgs): + __tablename__ = "arbitrum_sepolia_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/b3_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/b3_indexes.py new file mode 100644 index 0000000..f86c244 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/b3_indexes.py @@ -0,0 +1,10 @@ +# b3_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class B3BlockIndex(EvmBasedBlocks): + __tablename__ = "b3_blocks" + +class B3Reorgs(EvmBasedReorgs): + __tablename__ = "b3_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/b3_sepolia_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/b3_sepolia_indexes.py new file mode 100644 index 0000000..e0a5031 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/b3_sepolia_indexes.py @@ -0,0 +1,10 @@ +# b3_sepolia_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class B3SepoliaBlockIndex(EvmBasedBlocks): + __tablename__ = "b3_sepolia_blocks" + +class B3SepoliaReorgs(EvmBasedReorgs): + __tablename__ = "b3_sepolia_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/ethereum_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/ethereum_indexes.py new file mode 100644 index 0000000..84edafd --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/ethereum_indexes.py @@ -0,0 +1,10 @@ +# ethereum_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class EthereumBlockIndex(EvmBasedBlocks): + __tablename__ = "ethereum_blocks" + +class EthereumReorgs(EvmBasedReorgs): + __tablename__ = "ethereum_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/game7_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/game7_indexes.py new file mode 100644 index 0000000..7db1fd1 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/game7_indexes.py @@ -0,0 +1,13 @@ +# game7_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class Game7BlockIndex(EvmBasedBlocks): + __tablename__ = "game7_blocks" + + l1_block_number = Column(BigInteger, nullable=False) + + +class Game7Reorgs(EvmBasedReorgs): + __tablename__ = "game7_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/game7_testnet_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/game7_testnet_indexes.py new file mode 100644 index 0000000..4ba4f7d --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/game7_testnet_indexes.py @@ -0,0 +1,11 @@ +# game7_testnet_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class Game7TestnetBlockIndex(EvmBasedBlocks): + __tablename__ = "game7_testnet_blocks" + l1_block_number = Column(BigInteger, nullable=False) + +class Game7TestnetReorgs(EvmBasedReorgs): + __tablename__ = "game7_testnet_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/imx_zkevm_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/imx_zkevm_indexes.py new file mode 100644 index 0000000..e06388b --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/imx_zkevm_indexes.py @@ -0,0 +1,10 @@ +# imx_zkevm_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class ImxZkevmBlockIndex(EvmBasedBlocks): + __tablename__ = "imx_zkevm_blocks" + +class ImxZkevmReorgs(EvmBasedReorgs): + __tablename__ = "imx_zkevm_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/imx_zkevm_sepolia_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/imx_zkevm_sepolia_indexes.py new file mode 100644 index 0000000..40bb41e --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/imx_zkevm_sepolia_indexes.py @@ -0,0 +1,10 @@ +# imx_zkevm_sepolia_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class ImxZkevmSepoliaBlockIndex(EvmBasedBlocks): + __tablename__ = "imx_zkevm_sepolia_blocks" + +class ImxZkevmSepoliaReorgs(EvmBasedReorgs): + __tablename__ = "imx_zkevm_sepolia_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/mantle_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/mantle_indexes.py new file mode 100644 index 0000000..a93c2d8 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/mantle_indexes.py @@ -0,0 +1,10 @@ +# mantle_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class MantleBlockIndex(EvmBasedBlocks): + __tablename__ = "mantle_blocks" + +class MantleReorgs(EvmBasedReorgs): + __tablename__ = "mantle_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/mantle_sepolia_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/mantle_sepolia_indexes.py new file mode 100644 index 0000000..67c0979 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/mantle_sepolia_indexes.py @@ -0,0 +1,10 @@ +# mantle_sepolia_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class MantleSepoliaBlockIndex(EvmBasedBlocks): + __tablename__ = "mantle_sepolia_blocks" + +class MantleSepoliaReorgs(EvmBasedReorgs): + __tablename__ = "mantle_sepolia_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/polygon_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/polygon_indexes.py new file mode 100644 index 0000000..23a2c42 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/polygon_indexes.py @@ -0,0 +1,10 @@ +# polygon_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class PolygonBlockIndex(EvmBasedBlocks): + __tablename__ = "polygon_blocks" + +class PolygonReorgs(EvmBasedReorgs): + __tablename__ = "polygon_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/sepolia_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/sepolia_indexes.py new file mode 100644 index 0000000..13b0e1e --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/sepolia_indexes.py @@ -0,0 +1,10 @@ +# sepolia_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class SepoliaBlockIndex(EvmBasedBlocks): + __tablename__ = "sepolia_blocks" + +class SepoliaReorgs(EvmBasedReorgs): + __tablename__ = "sepolia_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/xai_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/xai_indexes.py new file mode 100644 index 0000000..92ec222 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/xai_indexes.py @@ -0,0 +1,11 @@ +# xai_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class XaiBlockIndex(EvmBasedBlocks): + __tablename__ = "xai_blocks" + l1_block_number = Column(BigInteger, nullable=False) + +class XaiReorgs(EvmBasedReorgs): + __tablename__ = "xai_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes/xai_sepolia_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes/xai_sepolia_indexes.py new file mode 100644 index 0000000..d9801b2 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes/xai_sepolia_indexes.py @@ -0,0 +1,11 @@ +# xai_sepolia_models.py + +from sqlalchemy import Column, BigInteger +from models_indexes.abstract_indexes import EvmBasedBlocks, EvmBasedReorgs + +class XaiSepoliaBlockIndex(EvmBasedBlocks): + __tablename__ = "xai_sepolia_blocks" + l1_block_number = Column(BigInteger, nullable=False) + +class XaiSepoliaReorgs(EvmBasedReorgs): + __tablename__ = "xai_sepolia_reorgs" diff --git a/moonstreamdb-v3/moonstreamdbv3/models_labels.py.tmpl b/moonstreamdb-v3/moonstreamdbv3/models_labels.py.tmpl new file mode 100644 index 0000000..3a98ccd --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/models_labels.py.tmpl @@ -0,0 +1,48 @@ +# {{ .BlockchainNameLower }}_labels.py + +from sqlalchemy import Index, text +from models.abstract_labels import EvmBasedLabel + +class {{ .BlockchainName }}Label(EvmBasedLabel): + __tablename__ = "{{ .BlockchainNameLower }}_labels" + + __table_args__ = ( + Index( + "ix_{{ .BlockchainNameLower }}_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_{{ .BlockchainNameLower }}_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_{{ .BlockchainNameLower }}_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_{{ .BlockchainNameLower }}_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_{{ .BlockchainNameLower }}_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_{{ .BlockchainNameLower }}_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) \ No newline at end of file diff --git a/moonstreamdb-v3/moonstreamdbv3/version.py b/moonstreamdb-v3/moonstreamdbv3/version.py new file mode 100644 index 0000000..d6ffd74 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/version.py @@ -0,0 +1,11 @@ +import os + +VERSION = "UNKNOWN" + +try: + PATH = os.path.abspath(os.path.dirname(__file__)) + VERSION_FILE = os.path.join(PATH, "version.txt") + with open(VERSION_FILE) as ifp: + VERSION = ifp.read().strip() +except: + pass diff --git a/moonstreamdb-v3/moonstreamdbv3/version.txt b/moonstreamdb-v3/moonstreamdbv3/version.txt new file mode 100644 index 0000000..fe04e7f --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/version.txt @@ -0,0 +1 @@ +0.0.20 diff --git a/moonstreamdb-v3/scm/pkg/blockchain-S0K5PY7LHKC4TFXZ/default.nix b/moonstreamdb-v3/scm/pkg/blockchain-S0K5PY7LHKC4TFXZ/default.nix new file mode 100644 index 0000000..5138ecb --- /dev/null +++ b/moonstreamdb-v3/scm/pkg/blockchain-S0K5PY7LHKC4TFXZ/default.nix @@ -0,0 +1,10 @@ +stdargs @ { scm, ... }: + +scm.schema { + guid = "S0K5PY7LHKC4TFXZ"; + name = "blockchain"; + upgrade_sql = ./upgrade.sql; + dependencies = [ + + ]; +} \ No newline at end of file diff --git a/moonstreamdb-v3/scm/pkg/blockchain-S0K5PY7LHKC4TFXZ/upgrade.sql b/moonstreamdb-v3/scm/pkg/blockchain-S0K5PY7LHKC4TFXZ/upgrade.sql new file mode 100644 index 0000000..e69de29 diff --git a/moonstreamdb-v3/scm/scm.nix b/moonstreamdb-v3/scm/scm.nix new file mode 100644 index 0000000..f35dbcf --- /dev/null +++ b/moonstreamdb-v3/scm/scm.nix @@ -0,0 +1,29 @@ +with builtins; +let + scm_repos = [ + (getEnv "SCM_GIT") + (fetchGit { + url = "git@gitlab.com:deltaex/schematic.git"; + rev = "ba5d7b40255e5da9a74e666dd88e309dae40fbd2"; + }) + ]; + scm_repo = head (filter (x: x != "") scm_repos); + scm = (import scm_repo { + verbose = true; + repos = [ + "." + (getEnv "MDP_GIT") + (fetchGit { + url = "git@github.com:moonstream-to/api.git"; + rev = "e27476ac5327d5494d2db16bb9bf781f9fc14e41"; + }) + ] ++ scm_repos; + }); +in rec { + schematic = scm.shell.overrideAttrs ( oldAttrs : { + shellHook = oldAttrs.shellHook + '' + [ -n "$ENV" -a "$ENV" != "dev" ] + source /home/moonstream/moonstream-db-v3-indexes-secrets/pg.env + ''; + }); +} diff --git a/moonstreamdb-v3/setup.py b/moonstreamdb-v3/setup.py new file mode 100644 index 0000000..34e36f0 --- /dev/null +++ b/moonstreamdb-v3/setup.py @@ -0,0 +1,40 @@ +from setuptools import find_packages, setup + +from moonstreamdbv3.version import VERSION + +long_description = "" +with open("README.md") as ifp: + long_description = ifp.read() + +setup( + name="moonstreamdb-v3", + version=VERSION, + author="Bugout.dev", + author_email="engineers@bugout.dev", + license="Apache License 2.0", + description="Moonstream V3 database", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/bugout-dev/moonstream", + platforms="all", + classifiers=[ + "Development Status :: 2 - Pre-Alpha", + "Intended Audience :: Developers", + "Natural Language :: English", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + python_requires=">=3.8", + packages=find_packages(), + package_data={"moonstreamdbv3": ["py.typed"]}, + zip_safe=False, + install_requires=["alembic", "psycopg2-binary", "sqlalchemy>=2.0.4"], + extras_require={ + "dev": ["black", "isort", "mypy"], + "distribute": ["setuptools", "twine", "wheel"], + }, +)