• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Permify / permify / 10528103096

23 Aug 2024 03:13PM UTC coverage: 66.726%. Remained the same
10528103096

Pull #1488

github

tolgaOzen
feat: update API requests and client-side calls with improved formatting
Pull Request #1488: feat: update API requests and client-side calls with improved formatting

6700 of 10041 relevant lines covered (66.73%)

113.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/storage/postgres/schemaWriter.go
1
package postgres
2

3
import (
4
        "context"
5
        "log/slog"
6

7
        "github.com/jackc/pgx/v5"
8

9
        "github.com/Permify/permify/internal/storage"
10
        "github.com/Permify/permify/internal/storage/postgres/utils"
11
        db "github.com/Permify/permify/pkg/database/postgres"
12
        base "github.com/Permify/permify/pkg/pb/base/v1"
13
)
14

15
// SchemaWriter - Structure for SchemaWriter
16
type SchemaWriter struct {
17
        database *db.Postgres
18
        // options
19
        txOptions pgx.TxOptions
20
}
21

22
// NewSchemaWriter creates a new SchemaWriter
23
func NewSchemaWriter(database *db.Postgres) *SchemaWriter {
×
24
        return &SchemaWriter{
×
25
                database:  database,
×
26
                txOptions: pgx.TxOptions{IsoLevel: pgx.ReadCommitted, AccessMode: pgx.ReadWrite},
×
27
        }
×
28
}
×
29

30
// WriteSchema writes a schema to the database
31
func (w *SchemaWriter) WriteSchema(ctx context.Context, schemas []storage.SchemaDefinition) (err error) {
×
32
        ctx, span := tracer.Start(ctx, "schema-writer.write-schema")
×
33
        defer span.End()
×
34

×
35
        slog.DebugContext(ctx, "writing schemas to the database", slog.Any("number_of_schemas", len(schemas)))
×
36

×
37
        insertBuilder := w.database.Builder.Insert(SchemaDefinitionTable).Columns("name, serialized_definition, version, tenant_id")
×
38

×
39
        for _, schema := range schemas {
×
40
                insertBuilder = insertBuilder.Values(schema.Name, schema.SerializedDefinition, schema.Version, schema.TenantID)
×
41
        }
×
42

43
        var query string
×
44
        var args []interface{}
×
45

×
46
        query, args, err = insertBuilder.ToSql()
×
47
        if err != nil {
×
48
                return utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER)
×
49
        }
×
50

51
        slog.DebugContext(ctx, "executing sql insert query", slog.Any("query", query), slog.Any("arguments", args))
×
52

×
53
        _, err = w.database.WritePool.Exec(ctx, query, args...)
×
54
        if err != nil {
×
55
                return utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_EXECUTION)
×
56
        }
×
57

58
        slog.DebugContext(ctx, "successfully wrote schemas to the database", slog.Any("number_of_schemas", len(schemas)))
×
59

×
60
        return nil
×
61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc