mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-14 23:37:28 -06:00
Add CreateTables func
This commit is contained in:
parent
13d4fda7fa
commit
f8e95ae128
4 changed files with 66 additions and 2 deletions
|
|
@ -19,13 +19,15 @@
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/apimodule"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db/model"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/apimodule"
|
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/router"
|
"github.com/superseriousbusiness/gotosocial/internal/router"
|
||||||
)
|
)
|
||||||
|
|
@ -64,3 +66,23 @@ func (m *accountModule) Route(r router.Router) error {
|
||||||
r.AttachHandler(http.MethodPatch, updateCredentialsPath, m.accountUpdateCredentialsPATCHHandler)
|
r.AttachHandler(http.MethodPatch, updateCredentialsPath, m.accountUpdateCredentialsPATCHHandler)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *accountModule) CreateTables(db db.DB) error {
|
||||||
|
models := []interface{}{
|
||||||
|
&model.User{},
|
||||||
|
&model.Account{},
|
||||||
|
&model.Follow{},
|
||||||
|
&model.FollowRequest{},
|
||||||
|
&model.Status{},
|
||||||
|
&model.Application{},
|
||||||
|
&model.EmailDomainBlock{},
|
||||||
|
&model.MediaAttachment{},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, m := range models {
|
||||||
|
if err := db.CreateTable(m); err != nil {
|
||||||
|
return fmt.Errorf("error creating table: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,15 @@
|
||||||
// Package apimodule is basically a wrapper for a lot of modules (in subdirectories) that satisfy the ClientAPIModule interface.
|
// Package apimodule is basically a wrapper for a lot of modules (in subdirectories) that satisfy the ClientAPIModule interface.
|
||||||
package apimodule
|
package apimodule
|
||||||
|
|
||||||
import "github.com/superseriousbusiness/gotosocial/internal/router"
|
import (
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/router"
|
||||||
|
)
|
||||||
|
|
||||||
// ClientAPIModule represents a chunk of code (usually contained in a single package) that adds a set
|
// ClientAPIModule represents a chunk of code (usually contained in a single package) that adds a set
|
||||||
// of functionalities and side effects to a router, by mapping routes and handlers onto it--in other words, a REST API ;)
|
// of functionalities and side effects to a router, by mapping routes and handlers onto it--in other words, a REST API ;)
|
||||||
// A ClientAPIMpdule corresponds roughly to one main path of the gotosocial REST api, for example /api/v1/accounts/ or /oauth/
|
// A ClientAPIMpdule corresponds roughly to one main path of the gotosocial REST api, for example /api/v1/accounts/ or /oauth/
|
||||||
type ClientAPIModule interface {
|
type ClientAPIModule interface {
|
||||||
Route(s router.Router) error
|
Route(s router.Router) error
|
||||||
|
CreateTables(db db.DB) error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,13 @@
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/apimodule"
|
"github.com/superseriousbusiness/gotosocial/internal/apimodule"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db/model"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/router"
|
"github.com/superseriousbusiness/gotosocial/internal/router"
|
||||||
)
|
)
|
||||||
|
|
@ -50,3 +52,20 @@ func (m *appModule) Route(s router.Router) error {
|
||||||
s.AttachHandler(http.MethodPost, appsPath, m.appsPOSTHandler)
|
s.AttachHandler(http.MethodPost, appsPath, m.appsPOSTHandler)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *appModule) CreateTables(db db.DB) error {
|
||||||
|
models := []interface{}{
|
||||||
|
&oauth.Client{},
|
||||||
|
&oauth.Token{},
|
||||||
|
&model.User{},
|
||||||
|
&model.Account{},
|
||||||
|
&model.Application{},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, m := range models {
|
||||||
|
if err := db.CreateTable(m); err != nil {
|
||||||
|
return fmt.Errorf("error creating table: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,13 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/apimodule"
|
"github.com/superseriousbusiness/gotosocial/internal/apimodule"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db/model"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/router"
|
"github.com/superseriousbusiness/gotosocial/internal/router"
|
||||||
)
|
)
|
||||||
|
|
@ -68,3 +70,20 @@ func (m *authModule) Route(s router.Router) error {
|
||||||
s.AttachMiddleware(m.oauthTokenMiddleware)
|
s.AttachMiddleware(m.oauthTokenMiddleware)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *authModule) CreateTables(db db.DB) error {
|
||||||
|
models := []interface{}{
|
||||||
|
&oauth.Client{},
|
||||||
|
&oauth.Token{},
|
||||||
|
&model.User{},
|
||||||
|
&model.Account{},
|
||||||
|
&model.Application{},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, m := range models {
|
||||||
|
if err := db.CreateTable(m); err != nil {
|
||||||
|
return fmt.Errorf("error creating table: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue