Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: schema generator #31

Merged
merged 60 commits into from Dec 10, 2021
Merged

feat: schema generator #31

merged 60 commits into from Dec 10, 2021

Conversation

rsbh
Copy link
Member

@rsbh rsbh commented Nov 21, 2021

No description provided.

remove slug from actions and namepaces
add namespaceId to roles and actions
@rsbh rsbh marked this pull request as ready for review December 5, 2021 19:38
store/postgres/policy.go Outdated Show resolved Hide resolved

func (p *Policy) AddPolicy(schema string) error {
request := &pb.WriteSchemaRequest{Schema: schema}
_, err := p.client.WriteSchema(context.Background(), request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets pass ctx ?

return transformedPolicies, nil
}

func (s Store) CreatePolicy(ctx context.Context, policyToCreate model.Policy) ([]model.Policy, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets try for txn in near future

return s.fetchNamespacePolicies(ctx, newPolicy.NamespaceID)
}

func (s Store) UpdatePolicy(ctx context.Context, id string, toUpdate model.Policy) ([]model.Policy, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets try for txn in near future

func (s Store) fetchNamespacePolicies(ctx context.Context, namespaceId string) ([]model.Policy, error) {
var fetchedPolicies []Policy

query := fmt.Sprintf("%s %s", listPolicyQuery, fmt.Sprintf("WHERE p.namespace_id='%s'", namespaceId))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHERE p.namespace_id='%s' -> WHERE p.namespace_id='$1'

getRoleQuery = `SELECT id, name, types, namespace, metadata, created_at, updated_at from roles where id=$1;`
listRolesQuery = `SELECT id, name, types, namespace, metadata, created_at, updated_at from roles;`
updateRoleQuery = `UPDATE roles SET name = $2, types = $3, namespace = $4, metadata = $5, updated_at = now() where id = $1;`
createRoleQuery = `INSERT into roles(id, name, types, namespace_id, namespac, metadata) values($1, $2, $3, $4, $4, $5) RETURNING id, name, types, namespace_id, metadata, created_at, updated_at;`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets fix the typo

func (s Store) fetchNamespacePolicies(ctx context.Context, namespaceId string) ([]model.Policy, error) {
var fetchedPolicies []Policy

query := fmt.Sprintf("%s %s", listPolicyQuery, "WHERE p.namespace_id='$1'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pgx does it - '$1' -> $1

@krtkvrm krtkvrm merged commit 0f57be2 into main Dec 10, 2021
@krtkvrm krtkvrm deleted the schema_generator branch December 10, 2021 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants