Skip to content

Commit

Permalink
#patch added /subscribe updates cmd, reduced api db data, added upd…
Browse files Browse the repository at this point in the history
…ate announcements

- added data comparison functionality
  - `NewCampaigns`, `NewEvents`, `WonPlanets`, `LostPlanets` and (unused) `NewMajorOrder?`
- updated db schema to include `prev_data` table for war updates functionality
- added new cron schedule for comparing data (for updates announcements)
- added new config var to centralise img urls
- updated `/subscribe` responses to now be entirely ephemeral
- updated `/subscribe` to test perms via sending messages, rather than responses
  • Loading branch information
jgaribsin committed Mar 14, 2024
1 parent a84c3b5 commit a699ce8
Show file tree
Hide file tree
Showing 25 changed files with 1,625 additions and 194 deletions.
12 changes: 5 additions & 7 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import 'dotenv/config';
// eslint-disable-next-line node/no-unpublished-import
import {defineConfig} from 'drizzle-kit';
import type {Config} from 'drizzle-kit';
import * as dotenv from 'dotenv';
dotenv.config();

export default defineConfig({
export default {
schema: './src/db/schema.ts',
out: './drizzle',
driver: 'pg',
dbCredentials: {
connectionString: process.env.DATABASE_URL as string,
ssl: true,
},
verbose: true,
strict: true,
});
} satisfies Config;
6 changes: 6 additions & 0 deletions drizzle/0006_first_captain_stacy.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS "prev_data" (
"time" integer PRIMARY KEY NOT NULL,
"war_id" integer NOT NULL,
"data" json NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
17 changes: 17 additions & 0 deletions drizzle/0007_narrow_dakota_north.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Unfortunately in current drizzle-kit version we can't automatically get name for primary key.
We are working on making it available!
Meanwhile you can:
1. Check pk name in your database, by running
SELECT constraint_name FROM information_schema.table_constraints
WHERE table_schema = 'public'
AND table_name = 'prev_data'
AND constraint_type = 'PRIMARY KEY';
2. Uncomment code below and paste pk name manually
Hope to release this update as soon as possible
*/

-- ALTER TABLE "prev_data" DROP CONSTRAINT "<constraint_name>";--> statement-breakpoint
ALTER TABLE "prev_data" ADD PRIMARY KEY ("war_id");
1 change: 1 addition & 0 deletions drizzle/0008_solid_slapstick.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "prev_data" ALTER COLUMN "created_at" DROP DEFAULT;
200 changes: 200 additions & 0 deletions drizzle/meta/0006_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"id": "54752ae7-26c6-4f6c-98f7-c66ec6f498bb",
"prevId": "e0fd70b8-3890-4740-a5fe-17b7396d4969",
"version": "5",
"dialect": "pg",
"tables": {
"announcement_channels": {
"name": "announcement_channels",
"schema": "",
"columns": {
"channel_id": {
"name": "channel_id",
"type": "varchar",
"primaryKey": true,
"notNull": true
},
"type": {
"name": "type",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
"guild_id": {
"name": "guild_id",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
"production": {
"name": "production",
"type": "boolean",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"api_data": {
"name": "api_data",
"schema": "",
"columns": {
"time": {
"name": "time",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"war_id": {
"name": "war_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"data": {
"name": "data",
"type": "json",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"persistent_messages": {
"name": "persistent_messages",
"schema": "",
"columns": {
"message_id": {
"name": "message_id",
"type": "varchar",
"primaryKey": true,
"notNull": true
},
"channel_id": {
"name": "channel_id",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
"type": {
"name": "type",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
"guild_id": {
"name": "guild_id",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
"production": {
"name": "production",
"type": "boolean",
"primaryKey": false,
"notNull": true
},
"deleted": {
"name": "deleted",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"prev_data": {
"name": "prev_data",
"schema": "",
"columns": {
"time": {
"name": "time",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"war_id": {
"name": "war_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"data": {
"name": "data",
"type": "json",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {
"user_perms": {
"name": "user_perms",
"values": {
"admin": "admin",
"officer": "officer"
}
}
},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
Loading

0 comments on commit a699ce8

Please sign in to comment.