Phase 1: chunk store, tile rendering pipeline, and Leaflet viewer
api: WS gateway with token auth (Postgres-backed servers table, seeded via `bun run seed`), column-granularity chunk store (hand-written SQL migrations, no drizzle-kit CLI — its config loader needs esbuild, which doesn't install cleanly here), dirty-chunk Redis stream producer with per-flush dedup, and a tile-serving route. worker: consumes the dirty-chunk stream via a proper consumer group, rasterizes each chunk's columns into a single-resolution top-down PNG (static pre-Flattening block-id palette), uploads to MinIO, and upserts the tile pointer. frontend: barebones Leaflet 2D viewer (CRS.Simple, one native zoom level) wired to /api/servers and /api/tiles. Object storage: tiles live in a dedicated `mcmapper-tiles` bucket on the existing shared MinIO instance (devstack-minio on octo-winsrv) instead of a per-stack container, via a scoped access key limited to that one bucket — see README's "Object storage" section. MINIO_SECRET_KEY is real and is deliberately not committed; docker-compose layers an untracked .env over .env.example for it. Full pipeline verified end-to-end against live containers: WS auth -> Postgres upsert -> deduped Redis dirty-chunk event -> worker rasterize -> MinIO upload -> tile fetch through the api route, including from the actual mod-side WS client (see MCMapper-Mod's matching commit).
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import postgres from "postgres";
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import * as schema from "./schema";
|
||||
|
||||
const sql = postgres(process.env.DATABASE_URL!);
|
||||
export const db = drizzle(sql, { schema });
|
||||
export { sql };
|
||||
@@ -0,0 +1,33 @@
|
||||
import { readdirSync, readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { sql } from "./client";
|
||||
|
||||
// Hand-written SQL migrations (see drizzle/*.sql) applied in filename order, tracked in a
|
||||
// `_migrations` table. No drizzle-kit CLI involved — its config loader needs esbuild, which
|
||||
// doesn't install cleanly in this environment; three tables don't need a migration framework.
|
||||
async function main() {
|
||||
await sql`CREATE TABLE IF NOT EXISTS "_migrations" ("name" text PRIMARY KEY, "applied_at" timestamptz NOT NULL DEFAULT now())`;
|
||||
|
||||
const dir = join(import.meta.dir, "..", "..", "drizzle");
|
||||
const files = readdirSync(dir).filter((f) => f.endsWith(".sql")).sort();
|
||||
|
||||
for (const file of files) {
|
||||
const [{ exists }] = await sql`SELECT EXISTS(SELECT 1 FROM "_migrations" WHERE "name" = ${file})`;
|
||||
if (exists) {
|
||||
console.log(`[migrate] skipping already-applied ${file}`);
|
||||
continue;
|
||||
}
|
||||
console.log(`[migrate] applying ${file}`);
|
||||
const contents = readFileSync(join(dir, file), "utf-8");
|
||||
await sql.unsafe(contents);
|
||||
await sql`INSERT INTO "_migrations" ("name") VALUES (${file})`;
|
||||
}
|
||||
|
||||
console.log("[migrate] up to date");
|
||||
await sql.end();
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error("[migrate] failed:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
import { pgTable, uuid, text, integer, smallint, timestamp, primaryKey } from "drizzle-orm/pg-core";
|
||||
|
||||
// One row per registered MC server. Phase 1 has no admin registration API yet (Phase 6) —
|
||||
// rows are created by `bun run seed` from MCMAPPER_SEED_SERVER_NAME/_TOKEN env vars.
|
||||
export const servers = pgTable("servers", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
name: text("name").notNull(),
|
||||
token: text("token").notNull().unique(),
|
||||
authMode: text("auth_mode").notNull().default("offline"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
|
||||
// Column-granularity world state: the topmost non-air block per (dimension, x, z), plus its
|
||||
// height. This is deliberately not full per-voxel storage — Phase 1 only needs enough to
|
||||
// rasterize a top-down 2D tile and to derive marker Y later. Full block/section data for 3D
|
||||
// meshing is a Phase 2 extension of this table, not built now (see plan's phased scope).
|
||||
export const chunkColumns = pgTable(
|
||||
"chunk_columns",
|
||||
{
|
||||
serverId: uuid("server_id")
|
||||
.notNull()
|
||||
.references(() => servers.id, { onDelete: "cascade" }),
|
||||
dimension: integer("dimension").notNull(),
|
||||
x: integer("x").notNull(),
|
||||
z: integer("z").notNull(),
|
||||
blockId: integer("block_id").notNull(),
|
||||
blockMeta: integer("block_meta").notNull(),
|
||||
height: smallint("height").notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => [primaryKey({ columns: [table.serverId, table.dimension, table.x, table.z] })],
|
||||
);
|
||||
|
||||
// Metadata pointer to a rendered tile PNG in MinIO — the binary itself never touches Postgres.
|
||||
// One row per (server, dimension, zoom, tileX, tileZ); zoom is always 0 until Phase 2 adds
|
||||
// multi-resolution tiles.
|
||||
export const tilePointers = pgTable(
|
||||
"tile_pointers",
|
||||
{
|
||||
serverId: uuid("server_id")
|
||||
.notNull()
|
||||
.references(() => servers.id, { onDelete: "cascade" }),
|
||||
dimension: integer("dimension").notNull(),
|
||||
zoom: integer("zoom").notNull().default(0),
|
||||
tileX: integer("tile_x").notNull(),
|
||||
tileZ: integer("tile_z").notNull(),
|
||||
storageKey: text("storage_key").notNull(),
|
||||
contentHash: text("content_hash").notNull(),
|
||||
renderedAt: timestamp("rendered_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => [
|
||||
primaryKey({ columns: [table.serverId, table.dimension, table.zoom, table.tileX, table.tileZ] }),
|
||||
],
|
||||
);
|
||||
Reference in New Issue
Block a user