Skip to content

Instantly share code, notes, and snippets.

@SegFault42
Created April 12, 2022 07:56
Show Gist options
  • Save SegFault42/9750bb2f1093b5a4a9f2801e7ae93e13 to your computer and use it in GitHub Desktop.
Save SegFault42/9750bb2f1093b5a4a9f2801e7ae93e13 to your computer and use it in GitHub Desktop.
Migration SQL to Firestore
package main
import (
"context"
"encoding/json"
"log"
firebase "firebase.google.com/go"
"google.golang.org/api/option"
)
type zombies []struct {
ID int `json:"id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt interface{} `json:"deleted_at"`
OperatingSystem string `json:"operating_system"`
Arch string `json:"arch"`
Hwid string `json:"hwid"`
Hostname string `json:"hostname"`
BotnetVersion string `json:"botnet_version"`
IP string `json:"ip"`
TotalMemory string `json:"total_memory"`
CPUNumbers string `json:"cpu_numbers"`
UpTime string `json:"up_time"`
}
func main() {
data := `` // <--- Your JSON sql dump goes here
var jsonstruct zombies // Replace with your struct
json.Unmarshal([]byte(data), &jsonstruct)
opt := option.WithCredentialsFile("") // <--- Your credentialsFile
config := &firebase.Config{ProjectID: ""} // <--- your projectID
app, err := firebase.NewApp(context.Background(), config, opt)
if err != nil {
log.Fatalf("error initializing app: %v\n", err)
}
// Use the application default credentials
ctx := context.Background()
client, err := app.Firestore(ctx)
if err != nil {
log.Fatalln(err)
}
defer client.Close()
for _, elem := range jsonstruct {
//store data
_, _, err = client.Collection("").Add(ctx, elem) // <--- Your collection name
if err != nil {
log.Fatalf("Failed adding aturing: %v", err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment