- Defined all 8 data models (Page, Widget, Bookmark, Note, TagAssociation, Group, Share, Preferences) - Implemented DynamoDB table creation for all tables with proper schemas - Added GSIs for efficient querying (UserBookmarksIndex, UserNotesIndex, TagItemsIndex, UserSharesIndex) - Comprehensive test coverage for all table schemas - Updated init-db command to create all tables
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"custom-start-page/internal/storage"
|
|
)
|
|
|
|
func main() {
|
|
endpoint := flag.String("endpoint", "http://localhost:8000", "DynamoDB endpoint")
|
|
flag.Parse()
|
|
|
|
ctx := context.Background()
|
|
|
|
log.Printf("Connecting to DynamoDB at %s...", *endpoint)
|
|
db, err := storage.NewDynamoDBClient(ctx, *endpoint)
|
|
if err != nil {
|
|
log.Fatalf("Failed to create DynamoDB client: %v", err)
|
|
}
|
|
|
|
// Create all tables
|
|
tables := []struct {
|
|
name string
|
|
create func(context.Context) error
|
|
}{
|
|
{"Users", db.CreateUsersTable},
|
|
{"Pages", db.CreatePagesTable},
|
|
{"Widgets", db.CreateWidgetsTable},
|
|
{"Bookmarks", db.CreateBookmarksTable},
|
|
{"Notes", db.CreateNotesTable},
|
|
{"TagAssociations", db.CreateTagAssociationsTable},
|
|
{"Groups", db.CreateGroupsTable},
|
|
{"SharedItems", db.CreateSharedItemsTable},
|
|
{"Preferences", db.CreatePreferencesTable},
|
|
}
|
|
|
|
for _, table := range tables {
|
|
log.Printf("Creating %s table...", table.name)
|
|
if err := table.create(ctx); err != nil {
|
|
log.Fatalf("Failed to create %s table: %v", table.name, err)
|
|
}
|
|
log.Printf("✓ %s table created successfully", table.name)
|
|
}
|
|
|
|
fmt.Println("\nDatabase initialization complete!")
|
|
fmt.Println("All tables created:")
|
|
for _, table := range tables {
|
|
fmt.Printf(" - %s\n", table.name)
|
|
}
|
|
os.Exit(0)
|
|
}
|