From 4f6ee8fc1fed2b9dbd5399a2a1e6f6223777bf8f Mon Sep 17 00:00:00 2001 From: Levi van Noort <73097785+levivannoort@users.noreply.github.com> Date: Mon, 11 May 2026 16:29:59 +0200 Subject: [PATCH 1/3] fix: update sdk-for-go dependency to v3.1.0 and add bigint column support --- go.mod | 2 +- go.sum | 4 +- internal/services/column/resource.go | 47 ++++++++++++++++--- .../services/function/variable_resource.go | 4 +- internal/services/site/variable_resource.go | 4 +- 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 5138cd2..473ebd4 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/appwrite/terraform-provider-appwrite go 1.25.0 require ( - github.com/appwrite/sdk-for-go/v3 v3.0.0 + github.com/appwrite/sdk-for-go/v3 v3.1.0 github.com/hashicorp/terraform-plugin-docs v0.24.0 github.com/hashicorp/terraform-plugin-framework v1.19.0 github.com/hashicorp/terraform-plugin-framework-validators v0.19.0 diff --git a/go.sum b/go.sum index 267dded..f063fe6 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,8 @@ github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= -github.com/appwrite/sdk-for-go/v3 v3.0.0 h1:kAdQeLkgN1ugyhYkgYQNl+r8G259FsOPcmmdhjqhHWU= -github.com/appwrite/sdk-for-go/v3 v3.0.0/go.mod h1:lAU9JHfkpFJQwfwC+DcmzGlpB7sZ5Eeiqkh/0kHrSy0= +github.com/appwrite/sdk-for-go/v3 v3.1.0 h1:G6dD2hdCewZzjTbecVe+Tyb+eQFbpFwADb50bpi9FCI= +github.com/appwrite/sdk-for-go/v3 v3.1.0/go.mod h1:lAU9JHfkpFJQwfwC+DcmzGlpB7sZ5Eeiqkh/0kHrSy0= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= diff --git a/internal/services/column/resource.go b/internal/services/column/resource.go index 99dbaec..5b91c8d 100644 --- a/internal/services/column/resource.go +++ b/internal/services/column/resource.go @@ -32,9 +32,10 @@ const ( colTypeEmail = "email" colTypeURL = "url" colTypeLine = "line" + colTypeBigInt = "bigint" ) -var allColumnTypes = "varchar, text, longtext, mediumtext, integer, float, boolean, enum, email, datetime, url, ip, point, line, polygon, relationship, string" +var allColumnTypes = "varchar, text, longtext, mediumtext, integer, bigint, float, boolean, enum, email, datetime, url, ip, point, line, polygon, relationship, string" type columnResource struct { clients *common.AppwriteClients @@ -105,7 +106,7 @@ func (r *columnResource) Schema(_ context.Context, _ resource.SchemaRequest, res Default: booldefault.StaticBool(false), }, "array": schema.BoolAttribute{ - Description: "Whether the column is an array. Applies to string, varchar, text, longtext, mediumtext, integer, float, boolean, enum, email, datetime, url, ip types.", + Description: "Whether the column is an array. Applies to string, varchar, text, longtext, mediumtext, integer, bigint, float, boolean, enum, email, datetime, url, ip types.", Optional: true, Computed: true, Default: booldefault.StaticBool(false), @@ -115,11 +116,11 @@ func (r *columnResource) Schema(_ context.Context, _ resource.SchemaRequest, res Optional: true, }, "min": schema.Int64Attribute{ - Description: "Minimum value. Applies to integer type.", + Description: "Minimum value. Applies to integer and bigint types.", Optional: true, }, "max": schema.Int64Attribute{ - Description: "Maximum value. Applies to integer type.", + Description: "Maximum value. Applies to integer and bigint types.", Optional: true, }, "float_min": schema.Float64Attribute{ @@ -322,6 +323,24 @@ func (r *columnResource) Create(ctx context.Context, req resource.CreateRequest, responseJSON, _ = json.Marshal(col) } + case colTypeBigInt: + var opts []tablesdb.CreateBigIntColumnOption + if !plan.Min.IsNull() { + opts = append(opts, tablesdbClient.WithCreateBigIntColumnMin(int(plan.Min.ValueInt64()))) + } + if !plan.Max.IsNull() { + opts = append(opts, tablesdbClient.WithCreateBigIntColumnMax(int(plan.Max.ValueInt64()))) + } + if !plan.DefaultStr.IsNull() { + opts = append(opts, tablesdbClient.WithCreateBigIntColumnDefault(parseIntDefault(plan.DefaultStr.ValueString()))) + } + opts = append(opts, tablesdbClient.WithCreateBigIntColumnArray(array)) + col, e := tablesdbClient.CreateBigIntColumn(databaseID, tableID, key, required, opts...) + err = e + if col != nil { + responseJSON, _ = json.Marshal(col) + } + case colTypeFloat: var opts []tablesdb.CreateFloatColumnOption if !plan.FloatMin.IsNull() { @@ -604,6 +623,20 @@ func (r *columnResource) Update(ctx context.Context, req resource.UpdateRequest, responseJSON, _ = json.Marshal(col) } + case colTypeBigInt: + var opts []tablesdb.UpdateBigIntColumnOption + if !plan.Min.IsNull() { + opts = append(opts, tablesdbClient.WithUpdateBigIntColumnMin(int(plan.Min.ValueInt64()))) + } + if !plan.Max.IsNull() { + opts = append(opts, tablesdbClient.WithUpdateBigIntColumnMax(int(plan.Max.ValueInt64()))) + } + col, e := tablesdbClient.UpdateBigIntColumn(databaseID, tableID, key, required, parseIntDefault(defaultStr), opts...) + err = e + if col != nil { + responseJSON, _ = json.Marshal(col) + } + case colTypeFloat: var opts []tablesdb.UpdateFloatColumnOption if !plan.FloatMin.IsNull() { @@ -768,7 +801,7 @@ func (r *columnResource) readResponseIntoState(ctx context.Context, responseJSON } if minVal, ok := generic["min"].(float64); ok { columnType := model.Type.ValueString() - if columnType == colTypeInteger { + if columnType == colTypeInteger || columnType == colTypeBigInt { model.Min = types.Int64Value(int64(minVal)) } else if columnType == colTypeFloat { model.FloatMin = types.Float64Value(minVal) @@ -776,7 +809,7 @@ func (r *columnResource) readResponseIntoState(ctx context.Context, responseJSON } if maxVal, ok := generic["max"].(float64); ok { columnType := model.Type.ValueString() - if columnType == colTypeInteger { + if columnType == colTypeInteger || columnType == colTypeBigInt { model.Max = types.Int64Value(int64(maxVal)) } else if columnType == colTypeFloat { model.FloatMax = types.Float64Value(maxVal) @@ -837,7 +870,7 @@ func (r *columnResource) readResponseIntoState(ctx context.Context, responseJSON } case float64: if !model.DefaultStr.IsNull() || model.DefaultStr.IsUnknown() { - if model.Type.ValueString() == colTypeInteger { + if model.Type.ValueString() == colTypeInteger || model.Type.ValueString() == colTypeBigInt { model.DefaultStr = types.StringValue(fmt.Sprintf("%d", int64(v))) } else { model.DefaultStr = types.StringValue(fmt.Sprintf("%g", v)) diff --git a/internal/services/function/variable_resource.go b/internal/services/function/variable_resource.go index f706d95..1243fb3 100644 --- a/internal/services/function/variable_resource.go +++ b/internal/services/function/variable_resource.go @@ -7,6 +7,7 @@ import ( "github.com/appwrite/sdk-for-go/v3/appwrite" "github.com/appwrite/sdk-for-go/v3/functions" + "github.com/appwrite/sdk-for-go/v3/id" "github.com/appwrite/sdk-for-go/v3/models" "github.com/appwrite/terraform-provider-appwrite/internal/common" "github.com/hashicorp/terraform-plugin-framework/path" @@ -120,6 +121,7 @@ func (r *variableResource) Create(ctx context.Context, req resource.CreateReques variable, err := functionsClient.CreateVariable( plan.FunctionID.ValueString(), + id.Unique(), plan.Key.ValueString(), plan.Value.ValueString(), createOpts..., @@ -178,6 +180,7 @@ func (r *variableResource) Update(ctx context.Context, req resource.UpdateReques functionsClient := appwrite.NewFunctions(r.clients.ClientForProject(projectID)) updateOpts := []functions.UpdateVariableOption{ + functionsClient.WithUpdateVariableKey(plan.Key.ValueString()), functionsClient.WithUpdateVariableValue(plan.Value.ValueString()), } if !plan.Secret.IsNull() { @@ -187,7 +190,6 @@ func (r *variableResource) Update(ctx context.Context, req resource.UpdateReques variable, err := functionsClient.UpdateVariable( plan.FunctionID.ValueString(), plan.ID.ValueString(), - plan.Key.ValueString(), updateOpts..., ) if err != nil { diff --git a/internal/services/site/variable_resource.go b/internal/services/site/variable_resource.go index cd9df3f..b1af6b9 100644 --- a/internal/services/site/variable_resource.go +++ b/internal/services/site/variable_resource.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/appwrite/sdk-for-go/v3/appwrite" + "github.com/appwrite/sdk-for-go/v3/id" "github.com/appwrite/sdk-for-go/v3/models" "github.com/appwrite/sdk-for-go/v3/sites" "github.com/appwrite/terraform-provider-appwrite/internal/common" @@ -120,6 +121,7 @@ func (r *variableResource) Create(ctx context.Context, req resource.CreateReques variable, err := sitesClient.CreateVariable( plan.SiteID.ValueString(), + id.Unique(), plan.Key.ValueString(), plan.Value.ValueString(), createOpts..., @@ -178,6 +180,7 @@ func (r *variableResource) Update(ctx context.Context, req resource.UpdateReques sitesClient := appwrite.NewSites(r.clients.ClientForProject(projectID)) updateOpts := []sites.UpdateVariableOption{ + sitesClient.WithUpdateVariableKey(plan.Key.ValueString()), sitesClient.WithUpdateVariableValue(plan.Value.ValueString()), } if !plan.Secret.IsNull() { @@ -187,7 +190,6 @@ func (r *variableResource) Update(ctx context.Context, req resource.UpdateReques variable, err := sitesClient.UpdateVariable( plan.SiteID.ValueString(), plan.ID.ValueString(), - plan.Key.ValueString(), updateOpts..., ) if err != nil { From 1bbd7b6530d1f5aae3ca754d3569c95fbb600431 Mon Sep 17 00:00:00 2001 From: Levi van Noort <73097785+levivannoort@users.noreply.github.com> Date: Mon, 11 May 2026 16:33:30 +0200 Subject: [PATCH 2/3] fix: update column type documentation to include bigint support --- docs/resources/tablesdb_column.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/resources/tablesdb_column.md b/docs/resources/tablesdb_column.md index 363b3c3..b9eea2d 100644 --- a/docs/resources/tablesdb_column.md +++ b/docs/resources/tablesdb_column.md @@ -120,19 +120,19 @@ resource "appwrite_tablesdb_column" "author" { - `database_id` (String) The database ID. - `table_id` (String) The table ID. -- `type` (String) The column type. One of: varchar, text, longtext, mediumtext, integer, float, boolean, enum, email, datetime, url, ip, point, line, polygon, relationship, string. +- `type` (String) The column type. One of: varchar, text, longtext, mediumtext, integer, bigint, float, boolean, enum, email, datetime, url, ip, point, line, polygon, relationship, string. ### Optional -- `array` (Boolean) Whether the column is an array. Applies to string, varchar, text, longtext, mediumtext, integer, float, boolean, enum, email, datetime, url, ip types. +- `array` (Boolean) Whether the column is an array. Applies to string, varchar, text, longtext, mediumtext, integer, bigint, float, boolean, enum, email, datetime, url, ip types. - `default` (String) Default value. Use "true"/"false" for boolean, numeric strings for integer/float. - `elements` (List of String) Array of allowed values. Required for enum type. - `encrypt` (Boolean) Whether the column is encrypted. Applies to string, varchar, text, longtext, mediumtext types. - `float_max` (Number) Maximum value. Applies to float type. - `float_min` (Number) Minimum value. Applies to float type. - `key` (String) The column key (name). -- `max` (Number) Maximum value. Applies to integer type. -- `min` (Number) Minimum value. Applies to integer type. +- `max` (Number) Maximum value. Applies to integer and bigint types. +- `min` (Number) Minimum value. Applies to integer and bigint types. - `on_delete` (String) Behavior when the parent document is deleted: restrict, cascade, setNull. Applies to relationship type. - `project_id` (String) The Appwrite project ID. Defaults to the provider-level project_id. - `related_table_id` (String) The ID of the related table. Required for relationship type. From e6b048062863058651b62d2a4c330f4256c3dd6f Mon Sep 17 00:00:00 2001 From: Levi van Noort <73097785+levivannoort@users.noreply.github.com> Date: Mon, 11 May 2026 16:44:02 +0200 Subject: [PATCH 3/3] fix: implement bigint parsing for default values in column creation and update --- internal/services/column/helpers.go | 16 +++++++++++++++- internal/services/column/resource.go | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/internal/services/column/helpers.go b/internal/services/column/helpers.go index 5a709b4..f60d94e 100644 --- a/internal/services/column/helpers.go +++ b/internal/services/column/helpers.go @@ -1,12 +1,26 @@ package column -import "strconv" +import ( + "fmt" + "strconv" +) func parseIntDefault(s string) int { v, _ := strconv.Atoi(s) return v } +func parseBigIntDefault(s string) (int, error) { + if s == "" { + return 0, nil + } + v, err := strconv.ParseInt(s, 10, 64) + if err != nil { + return 0, fmt.Errorf("invalid bigint default %q: %w", s, err) + } + return int(v), nil +} + func parseFloatDefault(s string) float64 { v, _ := strconv.ParseFloat(s, 64) return v diff --git a/internal/services/column/resource.go b/internal/services/column/resource.go index 5b91c8d..66d60fc 100644 --- a/internal/services/column/resource.go +++ b/internal/services/column/resource.go @@ -332,7 +332,12 @@ func (r *columnResource) Create(ctx context.Context, req resource.CreateRequest, opts = append(opts, tablesdbClient.WithCreateBigIntColumnMax(int(plan.Max.ValueInt64()))) } if !plan.DefaultStr.IsNull() { - opts = append(opts, tablesdbClient.WithCreateBigIntColumnDefault(parseIntDefault(plan.DefaultStr.ValueString()))) + def, parseErr := parseBigIntDefault(plan.DefaultStr.ValueString()) + if parseErr != nil { + resp.Diagnostics.AddError("Invalid default value", parseErr.Error()) + return + } + opts = append(opts, tablesdbClient.WithCreateBigIntColumnDefault(def)) } opts = append(opts, tablesdbClient.WithCreateBigIntColumnArray(array)) col, e := tablesdbClient.CreateBigIntColumn(databaseID, tableID, key, required, opts...) @@ -631,7 +636,12 @@ func (r *columnResource) Update(ctx context.Context, req resource.UpdateRequest, if !plan.Max.IsNull() { opts = append(opts, tablesdbClient.WithUpdateBigIntColumnMax(int(plan.Max.ValueInt64()))) } - col, e := tablesdbClient.UpdateBigIntColumn(databaseID, tableID, key, required, parseIntDefault(defaultStr), opts...) + def, parseErr := parseBigIntDefault(defaultStr) + if parseErr != nil { + resp.Diagnostics.AddError("Invalid default value", parseErr.Error()) + return + } + col, e := tablesdbClient.UpdateBigIntColumn(databaseID, tableID, key, required, def, opts...) err = e if col != nil { responseJSON, _ = json.Marshal(col)