feat(app): add data seed

master
Xeronith 2023-05-01 10:53:16 +03:30
rodzic e811d3d5f8
commit 55ed82112a
15 zmienionych plików z 52 dodań i 36 usunięć

Wyświetl plik

@ -7,6 +7,22 @@ import (
)
func Initialize(x IDispatcher) error {
// data seed
if !x.IdentityExists(0) {
identity := x.AddIdentityWithCustomId(0, "invalid", "0", false, EMPTY, EMPTY, EMPTY, "invalid@localhost", false, EMPTY, EMPTY, EMPTY, "0", false, EMPTY, EMPTY, EMPTY, EMPTY, NOT_SET, ACL_RESTRICTION_ACCESS_DENIED, NOT_SET, NOT_SET)
x.AddUser(identity.Id(), EMPTY)
}
if !x.IdentityExists(1) {
identity := x.AddIdentityWithCustomId(1, "root", "1", false, EMPTY, EMPTY, EMPTY, "root@localhost", false, EMPTY, EMPTY, EMPTY, "1", true, EMPTY, EMPTY, EMPTY, EMPTY, ACL_PERMISSION_ADMIN, ACL_RESTRICTION_NONE, NOT_SET, NOT_SET)
x.AddUser(identity.Id(), EMPTY)
}
if !x.CategoryTypeExists(0) {
categoryType := x.AddCategoryTypeWithCustomId(0, EMPTY)
_ = x.AddCategoryWithCustomId(0, categoryType.Id(), NOT_SET, EMPTY, EMPTY)
}
// system schedules
x.Ensure(
x.Schedule(jobs.SYSTEM_SCHEDULE_HOURLY, CRON_EVERY_HOUR, jobs.Hourly),

Wyświetl plik

@ -19,7 +19,7 @@ func newAccessControlsRepository(logger ILogger) IAccessControlsRepository {
}
func (repository *accessControlsRepository) Add(entity IAccessControlEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *accessControlsRepository) Add(entity IAccessControlEntity, edi
}
func (repository *accessControlsRepository) AddAtomic(transaction IRepositoryTransaction, entity IAccessControlEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -19,7 +19,7 @@ func newActivityPubFollowersRepository(logger ILogger) IActivityPubFollowersRepo
}
func (repository *activityPubFollowersRepository) Add(entity IActivityPubFollowerEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *activityPubFollowersRepository) Add(entity IActivityPubFollowe
}
func (repository *activityPubFollowersRepository) AddAtomic(transaction IRepositoryTransaction, entity IActivityPubFollowerEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -19,7 +19,7 @@ func newActivityPubIncomingActivitiesRepository(logger ILogger) IActivityPubInco
}
func (repository *activityPubIncomingActivitiesRepository) Add(entity IActivityPubIncomingActivityEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *activityPubIncomingActivitiesRepository) Add(entity IActivityP
}
func (repository *activityPubIncomingActivitiesRepository) AddAtomic(transaction IRepositoryTransaction, entity IActivityPubIncomingActivityEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -19,7 +19,7 @@ func newActivityPubOutgoingActivitiesRepository(logger ILogger) IActivityPubOutg
}
func (repository *activityPubOutgoingActivitiesRepository) Add(entity IActivityPubOutgoingActivityEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *activityPubOutgoingActivitiesRepository) Add(entity IActivityP
}
func (repository *activityPubOutgoingActivitiesRepository) AddAtomic(transaction IRepositoryTransaction, entity IActivityPubOutgoingActivityEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -19,7 +19,7 @@ func newCategoriesRepository(logger ILogger) ICategoriesRepository {
}
func (repository *categoriesRepository) Add(entity ICategoryEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *categoriesRepository) Add(entity ICategoryEntity, editor int64
}
func (repository *categoriesRepository) AddAtomic(transaction IRepositoryTransaction, entity ICategoryEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -19,7 +19,7 @@ func newCategoryTypesRepository(logger ILogger) ICategoryTypesRepository {
}
func (repository *categoryTypesRepository) Add(entity ICategoryTypeEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *categoryTypesRepository) Add(entity ICategoryTypeEntity, edito
}
func (repository *categoryTypesRepository) AddAtomic(transaction IRepositoryTransaction, entity ICategoryTypeEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -19,7 +19,7 @@ func newDocumentsRepository(logger ILogger) IDocumentsRepository {
}
func (repository *documentsRepository) Add(entity IDocumentEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *documentsRepository) Add(entity IDocumentEntity, editor int64)
}
func (repository *documentsRepository) AddAtomic(transaction IRepositoryTransaction, entity IDocumentEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -19,7 +19,7 @@ func newIdentitiesRepository(logger ILogger) IIdentitiesRepository {
}
func (repository *identitiesRepository) Add(entity IIdentityEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *identitiesRepository) Add(entity IIdentityEntity, editor int64
}
func (repository *identitiesRepository) AddAtomic(transaction IRepositoryTransaction, entity IIdentityEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -13,7 +13,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_DOCUMENT,
&sync.Mutex{},
"INSERT INTO `documents` (`id`, `content`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?);",
`INSERT INTO "documents" ("id", "content", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5);`,
func(entity IPipeEntity) Parameters {
e := entity.(IDocumentPipeEntity)
return Parameters{e.Id(), e.Content(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -22,7 +22,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_SYSTEM_SCHEDULE,
&sync.Mutex{},
"INSERT INTO `system_schedules` (`id`, `enabled`, `config`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?, ?);",
`INSERT INTO "system_schedules" ("id", "enabled", "config", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5, $6);`,
func(entity IPipeEntity) Parameters {
e := entity.(ISystemSchedulePipeEntity)
return Parameters{e.Id(), e.Enabled(), e.Config(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -31,7 +31,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_IDENTITY,
&sync.Mutex{},
"INSERT INTO `identities` (`id`, `username`, `phone_number`, `phone_number_confirmed`, `first_name`, `last_name`, `display_name`, `email`, `email_confirmed`, `avatar`, `banner`, `summary`, `token`, `multi_factor`, `hash`, `salt`, `public_key`, `private_key`, `permission`, `restriction`, `last_login`, `login_count`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
`INSERT INTO "identities" ("id", "username", "phone_number", "phone_number_confirmed", "first_name", "last_name", "display_name", "email", "email_confirmed", "avatar", "banner", "summary", "token", "multi_factor", "hash", "salt", "public_key", "private_key", "permission", "restriction", "last_login", "login_count", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25);`,
func(entity IPipeEntity) Parameters {
e := entity.(IIdentityPipeEntity)
return Parameters{e.Id(), e.Username(), e.PhoneNumber(), e.PhoneNumberConfirmed(), e.FirstName(), e.LastName(), e.DisplayName(), e.Email(), e.EmailConfirmed(), e.Avatar(), e.Banner(), e.Summary(), e.Token(), e.MultiFactor(), e.Hash(), e.Salt(), e.PublicKey(), e.PrivateKey(), e.Permission(), e.Restriction(), e.LastLogin(), e.LoginCount(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -40,7 +40,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_ACCESS_CONTROL,
&sync.Mutex{},
"INSERT INTO `access_controls` (`id`, `key`, `value`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?, ?);",
`INSERT INTO "access_controls" ("id", "key", "value", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5, $6);`,
func(entity IPipeEntity) Parameters {
e := entity.(IAccessControlPipeEntity)
return Parameters{e.Id(), e.Key(), e.Value(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -49,7 +49,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_REMOTE_ACTIVITY,
&sync.Mutex{},
"INSERT INTO `remote_activities` (`id`, `entry_point`, `duration`, `successful`, `error_message`, `remote_address`, `user_agent`, `event_type`, `timestamp`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
`INSERT INTO "remote_activities" ("id", "entry_point", "duration", "successful", "error_message", "remote_address", "user_agent", "event_type", "timestamp", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);`,
func(entity IPipeEntity) Parameters {
e := entity.(IRemoteActivityPipeEntity)
return Parameters{e.Id(), e.EntryPoint(), e.Duration(), e.Successful(), e.ErrorMessage(), e.RemoteAddress(), e.UserAgent(), e.EventType(), e.Timestamp(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -58,7 +58,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_CATEGORY_TYPE,
&sync.Mutex{},
"INSERT INTO `category_types` (`id`, `description`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?);",
`INSERT INTO "category_types" ("id", "description", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5);`,
func(entity IPipeEntity) Parameters {
e := entity.(ICategoryTypePipeEntity)
return Parameters{e.Id(), e.Description(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -67,7 +67,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_CATEGORY,
&sync.Mutex{},
"INSERT INTO `categories` (`id`, `category_type_id`, `category_id`, `title`, `description`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
`INSERT INTO "categories" ("id", "category_type_id", "category_id", "title", "description", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5, $6, $7, $8);`,
func(entity IPipeEntity) Parameters {
e := entity.(ICategoryPipeEntity)
return Parameters{e.Id(), e.CategoryTypeId(), e.CategoryId(), e.Title(), e.Description(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -76,7 +76,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_USER,
&sync.Mutex{},
"INSERT INTO `users` (`id`, `github`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?);",
`INSERT INTO "users" ("id", "github", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5);`,
func(entity IPipeEntity) Parameters {
e := entity.(IUserPipeEntity)
return Parameters{e.Id(), e.Github(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -85,7 +85,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_ACTIVITY_PUB_INCOMING_ACTIVITY,
&sync.Mutex{},
"INSERT INTO `activity_pub_incoming_activities` (`id`, `identity_id`, `unique_identifier`, `timestamp`, `from`, `to`, `content`, `raw`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
`INSERT INTO "activity_pub_incoming_activities" ("id", "identity_id", "unique_identifier", "timestamp", "from", "to", "content", "raw", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);`,
func(entity IPipeEntity) Parameters {
e := entity.(IActivityPubIncomingActivityPipeEntity)
return Parameters{e.Id(), e.IdentityId(), e.UniqueIdentifier(), e.Timestamp(), e.From(), e.To(), e.Content(), e.Raw(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -94,7 +94,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_ACTIVITY_PUB_OUTGOING_ACTIVITY,
&sync.Mutex{},
"INSERT INTO `activity_pub_outgoing_activities` (`id`, `identity_id`, `unique_identifier`, `timestamp`, `from`, `to`, `content`, `raw`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
`INSERT INTO "activity_pub_outgoing_activities" ("id", "identity_id", "unique_identifier", "timestamp", "from", "to", "content", "raw", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);`,
func(entity IPipeEntity) Parameters {
e := entity.(IActivityPubOutgoingActivityPipeEntity)
return Parameters{e.Id(), e.IdentityId(), e.UniqueIdentifier(), e.Timestamp(), e.From(), e.To(), e.Content(), e.Raw(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}
@ -103,7 +103,7 @@ func (repository *pipeRepository) GetPipeDescriptors() []*pipeDescriptor {
{
PIPE_ACTIVITY_PUB_FOLLOWER,
&sync.Mutex{},
"INSERT INTO `activity_pub_followers` (`id`, `handle`, `inbox`, `subject`, `activity`, `accepted`, `editor`, `queued_at`, `payload`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
`INSERT INTO "activity_pub_followers" ("id", "handle", "inbox", "subject", "activity", "accepted", "editor", "queued_at", "payload") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);`,
func(entity IPipeEntity) Parameters {
e := entity.(IActivityPubFollowerPipeEntity)
return Parameters{e.Id(), e.Handle(), e.Inbox(), e.Subject(), e.Activity(), e.Accepted(), e.GetEditor(), e.GetQueueTimestamp().UnixNano(), e.Payload()}

Wyświetl plik

@ -19,7 +19,7 @@ func newRemoteActivitiesRepository(logger ILogger) IRemoteActivitiesRepository {
}
func (repository *remoteActivitiesRepository) Add(entity IRemoteActivityEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *remoteActivitiesRepository) Add(entity IRemoteActivityEntity,
}
func (repository *remoteActivitiesRepository) AddAtomic(transaction IRepositoryTransaction, entity IRemoteActivityEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -19,7 +19,7 @@ func newSystemSchedulesRepository(logger ILogger) ISystemSchedulesRepository {
}
func (repository *systemSchedulesRepository) Add(entity ISystemScheduleEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *systemSchedulesRepository) Add(entity ISystemScheduleEntity, e
}
func (repository *systemSchedulesRepository) AddAtomic(transaction IRepositoryTransaction, entity ISystemScheduleEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

Wyświetl plik

@ -19,7 +19,7 @@ func newUsersRepository(logger ILogger) IUsersRepository {
}
func (repository *usersRepository) Add(entity IUserEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}
@ -29,7 +29,7 @@ func (repository *usersRepository) Add(entity IUserEntity, editor int64) error {
}
func (repository *usersRepository) AddAtomic(transaction IRepositoryTransaction, entity IUserEntity, editor int64) error {
if entity.Id() <= 0 {
if entity.Id() < 0 {
return ERROR_INVALID_PARAMETERS
}

2
go.mod
Wyświetl plik

@ -5,7 +5,7 @@ go 1.19
require (
github.com/robfig/cron v1.2.0
github.com/sendgrid/sendgrid-go v3.12.0+incompatible
github.com/xeronith/diamante v1.7.0
github.com/xeronith/diamante v1.7.1
google.golang.org/protobuf v1.28.1
)

4
go.sum
Wyświetl plik

@ -51,8 +51,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/xeronith/diamante v1.7.0 h1:/0iEPvZlvUGQuJSyFk+p3mC00i1kBnZyyun8PCcI4WE=
github.com/xeronith/diamante v1.7.0/go.mod h1:8eBxUVrSAajFctedef0WEaOGzrRSj3ZIyFn8bEwWmzQ=
github.com/xeronith/diamante v1.7.1 h1:nZdeuOxWN4rJBS4D9pSba2hqE942Y7qf9ISl3xVjtqE=
github.com/xeronith/diamante v1.7.1/go.mod h1:8eBxUVrSAajFctedef0WEaOGzrRSj3ZIyFn8bEwWmzQ=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=