Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Build tools and generation directives.
//
//go:generate templ generate ./internal/web/templates
package discrawl
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ require (
)

require (
github.com/a-h/templ v0.3.1001 // indirect
github.com/alexedwards/scs/v2 v2.9.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-chi/chi/v5 v5.2.5 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/oauth2 v0.35.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/time v0.14.0 // indirect
golang.org/x/tools v0.42.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.69.0 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
github.com/a-h/templ v0.3.1001 h1:yHDTgexACdJttyiyamcTHXr2QkIeVF1MukLy44EAhMY=
github.com/a-h/templ v0.3.1001/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo=
github.com/alexedwards/scs/v2 v2.9.0 h1:xa05mVpwTBm1iLeTMNFfAWpKUm4fXAW7CeAViqBVS90=
github.com/alexedwards/scs/v2 v2.9.0/go.mod h1:ToaROZxyKukJKT/xLcVQAChi5k6+Pn1Gvmdl7h3RRj8=
github.com/bwmarrin/discordgo v0.29.0 h1:FmWeXFaKUwrcL3Cx65c20bTRW+vOb6k8AnaP+EgjDno=
github.com/bwmarrin/discordgo v0.29.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug=
github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down Expand Up @@ -31,6 +37,8 @@ golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVo
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ=
golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -39,6 +47,8 @@ golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/admin_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *runtime) runInit(args []string) error {
defer func() { _ = client.Close() }()
syncerFactory := r.newSyncer
if syncerFactory == nil {
syncerFactory = func(client syncer.Client, s *store.Store, logger *slog.Logger) syncService {
syncerFactory = func(client syncer.Client, s store.DataStore, logger *slog.Logger) syncService {
return syncer.New(client, s, logger)
}
}
Expand Down
13 changes: 11 additions & 2 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type runtime struct {
syncer syncService
openStore func(context.Context, string) (*store.Store, error)
newDiscord func(config.Config) (discordClient, error)
newSyncer func(syncer.Client, *store.Store, *slog.Logger) syncService
newSyncer func(syncer.Client, store.DataStore, *slog.Logger) syncService
now func() time.Time
}

Expand Down Expand Up @@ -136,6 +136,12 @@ func (r *runtime) dispatch(rest []string) error {
return r.withServices(false, func() error { return r.runChannels(rest[1:]) })
case "status":
return r.withServices(false, func() error { return r.runStatus(rest[1:]) })
case "serve":
return r.runServe(rest[1:])
case "seed":
return r.runSeed(rest[1:])
case "migrate-db":
return r.runMigrateDB(rest[1:])
case "doctor":
return r.runDoctor(rest[1:])
default:
Expand Down Expand Up @@ -173,6 +179,9 @@ func (r *runtime) withServices(withDiscord bool, fn func() error) error {
if err != nil {
return nil, err
}
if token.IsUser {
return discord.NewUser(token.Token)
}
return discord.New(token.Token)
}
}
Expand All @@ -183,7 +192,7 @@ func (r *runtime) withServices(withDiscord bool, fn func() error) error {
defer func() { _ = r.client.Close() }()
syncerFactory := r.newSyncer
if syncerFactory == nil {
syncerFactory = func(client syncer.Client, s *store.Store, logger *slog.Logger) syncService {
syncerFactory = func(client syncer.Client, s store.DataStore, logger *slog.Logger) syncService {
return syncer.New(client, s, logger)
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestRuntimeInitSyncTailAndDoctor(t *testing.T) {
logger: discardLogger(),
openStore: store.Open,
newDiscord: func(config.Config) (discordClient, error) { return fakeDiscord, nil },
newSyncer: func(syncer.Client, *store.Store, *slog.Logger) syncService {
newSyncer: func(syncer.Client, store.DataStore, *slog.Logger) syncService {
return fakeSync
},
}
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestRuntimeConfiguresAttachmentTextOnSyncer(t *testing.T) {
logger: discardLogger(),
openStore: store.Open,
newDiscord: func(config.Config) (discordClient, error) { return &fakeDiscordClient{}, nil },
newSyncer: func(syncer.Client, *store.Store, *slog.Logger) syncService {
newSyncer: func(syncer.Client, store.DataStore, *slog.Logger) syncService {
return fakeSync
},
}
Expand Down
70 changes: 70 additions & 0 deletions internal/cli/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cli

import (
"flag"
"fmt"
"path/filepath"

"github.com/steipete/discrawl/internal/config"
"github.com/steipete/discrawl/internal/store"
)

func (r *runtime) runMigrateDB(args []string) error {
fs := flag.NewFlagSet("migrate-db", flag.ContinueOnError)
dryRun := fs.Bool("dry-run", false, "preview migration without writing")
dataDir := fs.String("data-dir", "", "target directory for per-guild DBs (default: ~/.discrawl)")
sourceDB := fs.String("source", "", "source discrawl.db path (default: from config)")
if err := fs.Parse(args); err != nil {
return usageErr(err)
}

cfg, err := config.Load(r.configPath)
if err != nil {
return configErr(err)
}
r.cfg = cfg

src := *sourceDB
if src == "" {
src, err = config.ExpandPath(cfg.DBPath)
if err != nil {
return configErr(err)
}
}

target := *dataDir
if target == "" {
target = filepath.Dir(src)
}

r.logger.Info("starting db migration",
"source", src,
"target", target,
"dry_run", *dryRun,
)

result, err := store.MigrateSplitDB(r.ctx, store.MigrateOptions{
SourceDB: src,
DataDir: target,
Logger: r.logger,
DryRun: *dryRun,
})
if err != nil {
return dbErr(err)
}

if *dryRun {
fmt.Fprintf(r.stdout, "Dry run: would migrate %d guild(s)\n", result.GuildCount)
for _, gr := range result.GuildResults {
fmt.Fprintf(r.stdout, " - %s (%s)\n", gr.GuildID, gr.GuildName)
}
return nil
}

fmt.Fprintf(r.stdout, "Migration complete: %d guild(s)\n", result.GuildCount)
for _, gr := range result.GuildResults {
fmt.Fprintf(r.stdout, " %s (%s): %d messages, %d members, %d channels\n",
gr.GuildID, gr.GuildName, gr.Messages, gr.Members, gr.Channels)
}
return nil
}
Loading