Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/resources/tablesdb_column.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
16 changes: 15 additions & 1 deletion internal/services/column/helpers.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
57 changes: 50 additions & 7 deletions internal/services/column/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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{
Expand Down Expand Up @@ -322,6 +323,29 @@ 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() {
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...)
err = e
if col != nil {
responseJSON, _ = json.Marshal(col)
}

case colTypeFloat:
var opts []tablesdb.CreateFloatColumnOption
if !plan.FloatMin.IsNull() {
Expand Down Expand Up @@ -604,6 +628,25 @@ 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())))
}
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)
}

case colTypeFloat:
var opts []tablesdb.UpdateFloatColumnOption
if !plan.FloatMin.IsNull() {
Expand Down Expand Up @@ -768,15 +811,15 @@ 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)
}
}
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)
Expand Down Expand Up @@ -837,7 +880,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))
Expand Down
4 changes: 3 additions & 1 deletion internal/services/function/variable_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...,
Expand Down Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion internal/services/site/variable_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...,
Expand Down Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
Loading