2020-07-01 11:08:20 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
2020-07-01 11:08:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type InitialMigration struct{}
|
|
|
|
|
|
|
|
// MigrationName returns the string initial migration
|
|
|
|
// which allows this store to be used as a migration
|
|
|
|
func (m InitialMigration) MigrationName() string {
|
|
|
|
return "initial migration"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Up initializes all the owned buckets of the underlying store
|
|
|
|
func (m InitialMigration) Up(ctx context.Context, store SchemaStore) error {
|
|
|
|
// please do not initialize anymore buckets here
|
|
|
|
// add them as a new migration to the list of migrations
|
|
|
|
// defined in NewInitialMigration.
|
|
|
|
|
|
|
|
for _, bucket := range [][]byte{
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
[]byte("authorizationsv1"),
|
|
|
|
[]byte("authorizationindexv1"),
|
|
|
|
[]byte("bucketsv1"),
|
|
|
|
[]byte("bucketindexv1"),
|
2020-11-04 15:33:31 +00:00
|
|
|
[]byte("dashboardsv2"),
|
|
|
|
[]byte("orgsdashboardsv1"),
|
|
|
|
[]byte("dashboardcellviewsv1"),
|
2020-07-01 11:08:20 +00:00
|
|
|
kvlogBucket,
|
|
|
|
kvlogIndex,
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
[]byte("labelsv1"),
|
|
|
|
[]byte("labelmappingsv1"),
|
|
|
|
[]byte("labelindexv1"),
|
|
|
|
[]byte("onboardingv1"),
|
|
|
|
[]byte("organizationsv1"),
|
|
|
|
[]byte("organizationindexv1"),
|
2020-07-01 11:08:20 +00:00
|
|
|
taskBucket,
|
|
|
|
taskRunBucket,
|
|
|
|
taskIndexBucket,
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
[]byte("userspasswordv1"),
|
2020-07-01 11:08:20 +00:00
|
|
|
scrapersBucket,
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
[]byte("secretsv1"),
|
2020-10-26 12:19:04 +00:00
|
|
|
[]byte("telegrafv1"),
|
|
|
|
[]byte("telegrafPluginsv1"),
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
[]byte("userresourcemappingsv1"),
|
2020-10-27 11:45:05 +00:00
|
|
|
[]byte("notificationRulev1"),
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
[]byte("usersv1"),
|
|
|
|
[]byte("userindexv1"),
|
2020-07-01 11:08:20 +00:00
|
|
|
sourceBucket,
|
|
|
|
// these are the "document" (aka templates) key prefixes
|
|
|
|
[]byte("templates/documents/content"),
|
|
|
|
[]byte("templates/documents/meta"),
|
|
|
|
// store base backed services
|
2020-10-28 15:22:14 +00:00
|
|
|
[]byte("checksv1"),
|
|
|
|
[]byte("checkindexv1"),
|
|
|
|
[]byte("notificationEndpointv1"),
|
|
|
|
[]byte("notificationEndpointIndexv1"),
|
2020-07-01 11:08:20 +00:00
|
|
|
variableBucket,
|
|
|
|
variableIndexBucket,
|
|
|
|
variableOrgsIndex,
|
2020-07-02 14:15:08 +00:00
|
|
|
// deprecated: removed in later migration
|
|
|
|
[]byte("sessionsv1"),
|
2020-07-01 11:08:20 +00:00
|
|
|
} {
|
|
|
|
if err := store.CreateBucket(ctx, bucket); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// seed initial sources (default source)
|
|
|
|
return store.Update(ctx, func(tx Tx) error {
|
|
|
|
return putAsJson(tx, sourceBucket, DefaultSource.ID, DefaultSource)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Down is a no operation required for service to be used as a migration
|
|
|
|
func (m InitialMigration) Down(ctx context.Context, store SchemaStore) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
func putAsJson(tx Tx, bucket []byte, id platform.ID, value interface{}) error {
|
2020-07-01 11:08:20 +00:00
|
|
|
data, err := json.Marshal(value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
encodedID, err := id.Encode()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := tx.Bucket(bucket)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return b.Put(encodedID, data)
|
|
|
|
}
|