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

Support Schema template for atlasgo.io #334

Open
datdao opened this issue Oct 12, 2023 · 2 comments
Open

Support Schema template for atlasgo.io #334

datdao opened this issue Oct 12, 2023 · 2 comments
Labels
question Further information is requested

Comments

@datdao
Copy link

datdao commented Oct 12, 2023

Hi guys,

I'm experimenting with using this library as the base for my language server, and I'm configuring a schema template for Atlas HCL. After a few days of trying to configure the schema to fit with Atlas, I'm stuck on some configuration about references. I hope you all can help me get through it

Here is an example of Atlas HCL to define database schema:

table "users" {
  column "id" {
    type = integer
  }
  primary_key {
    columns = [column.id]
  }
}

table "orders" {
  column "owner_id" {
    type = integer
  }
  foreign_key "owner_id" {
    columns     = [column.owner_id]
    ref_columns = [table.users.column.id]
    on_update   = NO_ACTION
    on_delete   = NO_ACTION
  }
}

The problems I'm facing are how to configure Nested block reference like table.users.column.id and Local reference like column.owner_id.

Screenshot 2023-10-12 at 18 52 31

I have tried defining ScopeID and Targetables, but they don't seem to work. I'm not sure if I'm missing some configuration, or if these features aren't supported yet.

Here is my config:

func tableBlockSchema() *schema.BlockSchema {
  return &schema.BlockSchema{
    Address: &schema.BlockAddrSchema{
      Steps: []schema.AddrStep{
        schema.StaticStep{Name: "table"},
        schema.LabelStep{Index: 0},
      },
      ScopeId:     "table",
      AsReference: true,
    },
    Labels: []*schema.LabelSchema{
      {
        Name: "name",
      },
    },
    Body: &schema.BodySchema{
      Blocks: map[string]*schema.BlockSchema{
        "column": &schema.BlockSchema{
          Address: &schema.BlockAddrSchema{
            Steps: []schema.AddrStep{
              schema.StaticStep{Name: "column"},
              schema.LabelStep{Index: 0},
            },
            ScopeId:     "column",
            AsReference: true,
          },
          Labels: []*schema.LabelSchema{
            {Name: "name"},
          },
          Type: schema.BlockTypeObject,
        },
        "primary_key": &schema.BlockSchema{
          Type: schema.BlockTypeObject,
          Body: &schema.BodySchema{
            Attributes: map[string]*schema.AttributeSchema{
              "columns": &schema.AttributeSchema{
                Constraint: schema.Set{
                  Elem: schema.OneOf{
                    schema.Reference{OfScopeId: "column"},
                  },
                },
              },
            },
          },
        },
        "foreign_key": &schema.BlockSchema{
          Type: schema.BlockTypeObject,
          Body: &schema.BodySchema{
            Attributes: map[string]*schema.AttributeSchema{
              "columns": &schema.AttributeSchema{
                Constraint: schema.Set{
                  Elem: schema.OneOf{
                    schema.Reference{OfScopeId: "column"},
                  },
                },
              },
              "ref_columns": &schema.AttributeSchema{
                Constraint: schema.Set{
                  Elem: schema.OneOf{
                    schema.Reference{OfScopeId: "table"},
                  },
                },
              },
            },
          },
        },
      },
    },
  }
}
@dbanck dbanck added the question Further information is requested label Oct 13, 2023
@radeksimko
Copy link
Member

Hi @datdao
First of all, thanks for the interest in the library. I'd caution (as per the Readme) that it's still very much work in progress and the API may change, but LS for AtlasGo looks exactly like a use case this library was designed to potentially solve. In practice though we never tested it outside of Terraform, so YMMV.


Would you mind also providing the code which decodes the configuration based on the schema, so I can understand what exactly you expect to happen and what isn't working?

FWIW We have a relatively decent test coverage of most parts of the code base, so that may help understand how things work, even if they may look confusing at first.

@giautm
Copy link
Contributor

giautm commented Oct 19, 2023

@radeksimko: Hello, I'm a co-worker with @datdao. Thank you for your response here. We also want to contribute to this support if it's missing / undevelopment yet.

First, we will try to send a PR to demonstration of config using your existing unit-test. Then, we can discus what is the next step for this support.

@radeksimko radeksimko removed their assignment Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants