feat: D1 upgrade: deployment and migration process DONE!

This commit is contained in:
lyc8503 committed 2026-01-03 23:06:32 +08:00
1 parent 0258ae1ddc
commit 3de3640d17
12 files changed
+278 -76

No files matched your search

+21 -26
View File
@@ -16,49 +16,49 @@ variable "CLOUDFLARE_ACCOUNT_ID" {
type = string
}
resource "cloudflare_workers_kv_namespace" "uptimeflare_kv" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
title = "uptimeflare_kv"
variable "enable_do_migration" {
type = bool
default = false
}
resource "cloudflare_d1_database" "uptimeflare_d1" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
name = "uptimeflare_d1"
primary_location_hint = "wnam"
account_id = var.CLOUDFLARE_ACCOUNT_ID
name = "uptimeflare_d1"
read_replication = {
mode = "auto"
}
}
resource "cloudflare_workers_script" "uptimeflare_worker" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
script_name = "uptimeflare_worker"
main_module = "worker/dist/index.js"
content_file = "worker/dist/index.js"
content_sha256 = filesha256("worker/dist/index.js")
compatibility_date = "2025-04-02"
account_id = var.CLOUDFLARE_ACCOUNT_ID
script_name = "uptimeflare_worker"
main_module = "worker/dist/index.js"
content_file = "worker/dist/index.js"
content_sha256 = filesha256("worker/dist/index.js")
compatibility_date = "2025-04-02"
compatibility_flags = ["nodejs_compat"]
observability = {
enabled = true
logs = {
enabled = true
enabled = true
invocation_logs = true
}
}
migrations = var.enable_do_migration ? {
new_tag = "v1"
new_sqlite_classes = ["RemoteChecker"]
} : null
bindings = [{
name = "REMOTE_CHECKER_DO"
class_name = "RemoteChecker"
type = "durable_object_namespace"
}, {
name = "UPTIMEFLARE_STATE"
type = "kv_namespace"
namespace_id = cloudflare_workers_kv_namespace.uptimeflare_kv.id
}, {
}, {
name = "UPTIMEFLARE_D1"
type = "d1"
id = cloudflare_d1_database.uptimeflare_d1.id
id = cloudflare_d1_database.uptimeflare_d1.id
}]
}
@@ -66,7 +66,7 @@ resource "cloudflare_workers_cron_trigger" "uptimeflare_worker_cron" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
script_name = cloudflare_workers_script.uptimeflare_worker.script_name
schedules = [{
cron = "* * * * *" # every 1 minute, you can reduce the KV write by increase the worker settings of `kvWriteCooldownMinutes`
cron = "* * * * *" # every 1 minute, you can reduce the write counts by increase the worker settings of `kvWriteCooldownMinutes`
}]
}
@@ -81,11 +81,6 @@ resource "cloudflare_pages_project" "uptimeflare" {
fail_open = false
}
production = {
kv_namespaces = {
UPTIMEFLARE_STATE = {
namespace_id = cloudflare_workers_kv_namespace.uptimeflare_kv.id
}
}
d1_databases = {
UPTIMEFLARE_D1 = {
id = cloudflare_d1_database.uptimeflare_d1.id
@@ -93,7 +88,7 @@ resource "cloudflare_pages_project" "uptimeflare" {
}
compatibility_date = "2025-04-02"
compatibility_flags = ["nodejs_compat"]
fail_open = false
fail_open = false
}
}