Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type TestSettings struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
AccountID uint `gorm:"not null;uniqueIndex"`
|
||||
Name string `gorm:"size:50"`
|
||||
AutoProvision bool `gorm:"default:true"`
|
||||
Active bool `gorm:"default:true"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
db, err := gorm.Open(sqlite.Open("test_bool.db"), &gorm.Config{})
|
||||
if err != nil {
|
||||
fmt.Println("ERROR:", err)
|
||||
return
|
||||
}
|
||||
db.AutoMigrate(&TestSettings{})
|
||||
|
||||
// Approach: Create with AutoProvision=true (non-zero), then update to false
|
||||
s := TestSettings{AccountID: 1, Name: "test1", AutoProvision: true, Active: true}
|
||||
db.Create(&s)
|
||||
fmt.Printf("After Create: ID=%d\n", s.ID)
|
||||
|
||||
// Now update AutoProvision to false
|
||||
db.Model(&TestSettings{}).Where("id = ?", s.ID).Update("auto_provision", false)
|
||||
|
||||
var r TestSettings
|
||||
db.First(&r, s.ID)
|
||||
fmt.Printf("Final: AutoProvision=%v, Active=%v, ID=%d\n", r.AutoProvision, r.Active, r.ID)
|
||||
|
||||
// Also test: what happens if we try Create with Active=false?
|
||||
s2 := TestSettings{AccountID: 2, Name: "test2", AutoProvision: true, Active: true}
|
||||
db.Create(&s2)
|
||||
db.Model(&TestSettings{}).Where("id = ?", s2.ID).Updates(map[string]interface{}{"auto_provision": false, "active": false})
|
||||
|
||||
var r2 TestSettings
|
||||
db.First(&r2, s2.ID)
|
||||
fmt.Printf("Final2: AutoProvision=%v, Active=%v\n", r2.AutoProvision, r2.Active)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import glob
|
||||
|
||||
model_dir = "/home/yanghao05/Workspace/gochat/internal/model"
|
||||
channel_dir = "/home/yanghao05/Workspace/gochat/internal/model/channel"
|
||||
|
||||
for pattern_dir in [model_dir, channel_dir]:
|
||||
for f in glob.glob(os.path.join(pattern_dir, "*.go.txt")):
|
||||
newname = f[:-4] # remove .txt suffix
|
||||
print(f"Renaming: {f} -> {newname}")
|
||||
os.rename(f, newname)
|
||||
|
||||
# Cleanup
|
||||
for cleanup in [
|
||||
os.path.join(model_dir, "test_write.go"),
|
||||
os.path.join(model_dir, "base_test.txt"),
|
||||
"/home/yanghao05/Workspace/gochat/rename_models.sh.txt",
|
||||
]:
|
||||
if os.path.exists(cleanup):
|
||||
print(f"Removing: {cleanup}")
|
||||
os.remove(cleanup)
|
||||
|
||||
print("Done!")
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
cd /home/yanghao05/Workspace/gochat
|
||||
|
||||
for f in internal/model/*.go.txt; do
|
||||
newname="${f%.txt}"
|
||||
mv "$f" "$newname"
|
||||
done
|
||||
|
||||
for f in internal/model/channel/*.go.txt; do
|
||||
newname="${f%.txt}"
|
||||
mv "$f" "$newname"
|
||||
done
|
||||
|
||||
rm -f internal/model/test_write.go internal/model/base_test.txt rename_models.sh.txt
|
||||
|
||||
echo "Done"
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
# Rename all .go.txt model files to .go files in GoChat project
|
||||
# Run this script from: cd /home/yanghao05/Workspace/gochat
|
||||
|
||||
cd /home/yanghao05/Workspace/gochat
|
||||
|
||||
echo "Renaming .go.txt files to .go files..."
|
||||
|
||||
# Rename in internal/model/
|
||||
for f in internal/model/*.go.txt; do
|
||||
if [ -f "$f" ]; then
|
||||
newname="${f%.txt}"
|
||||
# Remove existing .go file if it exists (they're skeletal stubs)
|
||||
if [ -f "$newname" ]; then
|
||||
echo "Replacing: $newname"
|
||||
else
|
||||
echo "Creating: $newname"
|
||||
fi
|
||||
mv "$f" "$newname"
|
||||
fi
|
||||
done
|
||||
|
||||
# Rename in internal/model/channel/
|
||||
for f in internal/model/channel/*.go.txt; do
|
||||
if [ -f "$f" ]; then
|
||||
newname="${f%.txt}"
|
||||
if [ -f "$newname" ]; then
|
||||
echo "Replacing: $newname"
|
||||
else
|
||||
echo "Creating: $newname"
|
||||
fi
|
||||
mv "$f" "$newname"
|
||||
fi
|
||||
done
|
||||
|
||||
# Remove the old test/placeholder files
|
||||
rm -f internal/model/test_write.go
|
||||
rm -f internal/model/base_test.txt
|
||||
rm -f rename_models.sh.txt
|
||||
|
||||
echo "Done! All .go.txt files renamed to .go"
|
||||
|
||||
# List all model files
|
||||
echo ""
|
||||
echo "Model files in internal/model/:"
|
||||
ls -1 internal/model/*.go 2>/dev/null
|
||||
echo ""
|
||||
echo "Channel model files in internal/model/channel/:"
|
||||
ls -1 internal/model/channel/*.go 2>/dev/null
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
cd /home/yanghao05/Workspace/gochat
|
||||
export GOROOT=/home/yanghao05/.local/go
|
||||
export PATH=$GOROOT/bin:$PATH
|
||||
|
||||
echo "=== BUILD ==="
|
||||
go build ./... 2>&1
|
||||
echo "BUILD_EXIT=$?"
|
||||
|
||||
echo "=== REPO TEST COMPILE ==="
|
||||
go test -c ./internal/repository/ -o /dev/null 2>&1
|
||||
echo "REPO_EXIT=$?"
|
||||
|
||||
echo "=== SERVICE TEST COMPILE ==="
|
||||
go test -c ./internal/service/ -o /dev/null 2>&1
|
||||
echo "SERVICE_EXIT=$?"
|
||||
|
||||
echo "=== HANDLER V1 TEST COMPILE ==="
|
||||
go test -c ./internal/handler/api/v1/ -o /dev/null 2>&1
|
||||
echo "V1_EXIT=$?"
|
||||
|
||||
echo "=== HANDLER WIDGET TEST COMPILE ==="
|
||||
go test -c ./internal/handler/widget/ -o /dev/null 2>&1
|
||||
echo "WIDGET_EXIT=$?"
|
||||
|
||||
echo "=== RUN REPO TESTS ==="
|
||||
go test ./internal/repository/ -run TestWidgetOfflineMessage -v -count=1 2>&1 | head -60
|
||||
echo "REPO_TEST_EXIT=$?"
|
||||
|
||||
echo "=== RUN SERVICE TESTS ==="
|
||||
go test ./internal/service/ -run TestWidgetService_SubmitOfflineMessage -v -count=1 2>&1 | head -60
|
||||
echo "SERVICE_TEST_EXIT=$?"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
cd /home/yanghao05/Workspace/gochat
|
||||
go build ./... 2>&1
|
||||
echo "---"
|
||||
go vet ./... 2>&1
|
||||
Reference in New Issue
Block a user