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
36 changes: 36 additions & 0 deletions .github/workflows/migrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: D1 Migrations

on:
push:
branches: [main]
paths:
- "apps/operator/migrations/**"

permissions: {}

concurrency:
group: d1-migrations-${{ github.ref }}
cancel-in-progress: false

jobs:
migrate:
name: apply-migrations
runs-on: ubuntu-latest
timeout-minutes: 10
environment: production
permissions:
contents: read
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
with:
persist-credentials: false
fetch-depth: 1

- name: Setup
uses: ./.github/actions/setup

- name: Apply D1 migrations
run: pnpm --filter @repo/operator exec wrangler d1 migrations apply switch-operator-db --remote
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
8 changes: 8 additions & 0 deletions apps/operator/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "drizzle-kit";

// eslint-disable-next-line import/no-default-export
export default defineConfig({
out: "./migrations",
schema: "./src/db/schema.ts",
dialect: "sqlite",
});
21 changes: 21 additions & 0 deletions apps/operator/migrations/0000_acoustic_shape.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE `schedules` (
`id` text PRIMARY KEY NOT NULL,
`chat_id` integer NOT NULL,
`schedule_type` text NOT NULL,
`hour` integer,
`minute` integer DEFAULT 0,
`day_of_week` integer,
`day_of_month` integer,
`timezone` text DEFAULT 'UTC' NOT NULL,
`fixed_message` text,
`message_prompt` text,
`source_url` text,
`state_json` text,
`description` text NOT NULL,
`active` integer DEFAULT true NOT NULL,
`next_run_at` text NOT NULL,
`retry_count` integer DEFAULT 0 NOT NULL,
`created_at` text NOT NULL
);
--> statement-breakpoint
CREATE INDEX `idx_schedules_next_run` ON `schedules` (`active`,`next_run_at`);
7 changes: 7 additions & 0 deletions apps/operator/migrations/0001_cool_thanos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE `pending_actions` (
`chat_id` integer PRIMARY KEY NOT NULL,
`action_type` text NOT NULL,
`payload` text NOT NULL,
`description` text NOT NULL,
`expires_at` text NOT NULL
);
157 changes: 157 additions & 0 deletions apps/operator/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"version": "6",
"dialect": "sqlite",
"id": "c0ba48da-50d8-497b-9a7b-721b8aa7b578",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"schedules": {
"name": "schedules",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"chat_id": {
"name": "chat_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"schedule_type": {
"name": "schedule_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"hour": {
"name": "hour",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"minute": {
"name": "minute",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"day_of_week": {
"name": "day_of_week",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"day_of_month": {
"name": "day_of_month",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"timezone": {
"name": "timezone",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'UTC'"
},
"fixed_message": {
"name": "fixed_message",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"message_prompt": {
"name": "message_prompt",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"source_url": {
"name": "source_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"state_json": {
"name": "state_json",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"active": {
"name": "active",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": true
},
"next_run_at": {
"name": "next_run_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"retry_count": {
"name": "retry_count",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"idx_schedules_next_run": {
"name": "idx_schedules_next_run",
"columns": ["active", "next_run_at"],
"isUnique": false
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
Loading
Loading