-
-
Notifications
You must be signed in to change notification settings - Fork 169
feat: Add SingleStore Helios database support #518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2cc278b
245fb3f
f5fdaa4
d4f6f85
a91f2fe
5d6f271
1fdac04
b0eae64
4f318a3
da684c9
18b6804
80da37c
6ad6671
66555cc
7e11389
fdcd32c
d51747e
9943774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": ["@better-t-stack/backend", "web"] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-better-t-stack": minor | ||
--- | ||
|
||
Add SingleStore Helios database support |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import path from "node:path"; | ||
import { log } from "@clack/prompts"; | ||
import fs from "fs-extra"; | ||
import pc from "picocolors"; | ||
import type { ProjectConfig } from "../../types"; | ||
import { | ||
addEnvVariablesToFile, | ||
type EnvVariable, | ||
} from "../project-generation/env-setup"; | ||
|
||
type SingleStoreHeliosConfig = { | ||
connectionString: string; | ||
}; | ||
|
||
async function writeEnvFile( | ||
projectDir: string, | ||
config?: SingleStoreHeliosConfig, | ||
) { | ||
try { | ||
const envPath = path.join(projectDir, "apps/server", ".env"); | ||
const variables: EnvVariable[] = [ | ||
{ | ||
key: "DATABASE_URL", | ||
value: | ||
config?.connectionString ?? | ||
"singlestore://username:password@host:port/database?ssl={}", | ||
condition: true, | ||
}, | ||
]; | ||
await addEnvVariablesToFile(envPath, variables); | ||
} catch (_error) { | ||
log.error("Failed to update environment configuration"); | ||
} | ||
} | ||
|
||
function displayManualSetupInstructions() { | ||
log.info(` | ||
${pc.green("SingleStore Helios Manual Setup Instructions:")} | ||
|
||
1. Sign up for SingleStore Cloud at: | ||
${pc.blue("https://www.singlestore.com/cloud")} | ||
|
||
2. Create a new workspace from the dashboard | ||
|
||
3. Get your connection string from the workspace details: | ||
Format: ${pc.dim("singlestore://USERNAME:PASSWORD@HOST:PORT/DATABASE?ssl={}")} | ||
|
||
4. Add the connection string to your .env file: | ||
${pc.dim('DATABASE_URL="your_connection_string"')} | ||
|
||
${pc.yellow("Important:")} | ||
- The connection string MUST include ${pc.bold("ssl={}")} at the end | ||
- Use the singlestore:// protocol for SingleStore connections | ||
- SingleStore requires SSL connections for cloud deployments`); | ||
} | ||
|
||
export async function setupSingleStoreHelios(config: ProjectConfig) { | ||
const { projectDir } = config; | ||
|
||
try { | ||
const serverDir = path.join(projectDir, "apps/server"); | ||
await fs.ensureDir(serverDir); | ||
await writeEnvFile(projectDir); | ||
|
||
log.success( | ||
pc.green( | ||
"SingleStore Helios setup complete! Please update the connection string in .env file.", | ||
), | ||
); | ||
|
||
displayManualSetupInstructions(); | ||
} catch (error) { | ||
log.error(pc.red("SingleStore Helios setup failed")); | ||
if (error instanceof Error) { | ||
log.error(pc.red(error.message)); | ||
} | ||
|
||
try { | ||
await writeEnvFile(projectDir); | ||
displayManualSetupInstructions(); | ||
} catch {} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { defineConfig } from "drizzle-kit"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default defineConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
schema: "./src/db/schema", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
out: "./src/db/migrations", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
dialect: "singlestore", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
dbCredentials: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
url: process.env.DATABASE_URL || "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Load .env early and fail fast when DATABASE_URL is missing drizzle-kit runs this file directly; without importing dotenv, DATABASE_URL often won’t be present. Falling back to "" hides config mistakes. Apply this diff: +import "dotenv/config";
import { defineConfig } from "drizzle-kit";
-export default defineConfig({
- schema: "./src/db/schema",
- out: "./src/db/migrations",
- dialect: "singlestore",
- dbCredentials: {
- url: process.env.DATABASE_URL || "",
- },
-});
+const url = process.env.DATABASE_URL;
+if (!url) {
+ throw new Error("DATABASE_URL is not set. Please set it (SingleStore Helios requires TLS).");
+}
+
+export default defineConfig({
+ schema: "./src/db/schema",
+ out: "./src/db/migrations",
+ dialect: "singlestore",
+ dbCredentials: {
+ url,
+ },
+}); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,6 @@ | ||||||||||||||||||||||||||||||||||||
import mysql from "mysql2/promise"; | ||||||||||||||||||||||||||||||||||||
import { drizzle } from "drizzle-orm/singlestore"; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
const pool = mysql.createPool(process.env.DATABASE_URL || ""); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
export const db = drizzle({ client: pool }); | ||||||||||||||||||||||||||||||||||||
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fail fast on missing DATABASE_URL and avoid empty-string fallback Silently passing "" to createPool will defer failures to runtime and make debugging harder. Also, Helios requires TLS; ensure the env-provided URL includes ssl params or configure ssl in code. Apply this diff to validate the env and add basic pool options (keeps URL-driven SSL; if you prefer code-driven SSL, I can provide that too): -const pool = mysql.createPool(process.env.DATABASE_URL || "");
+const url = process.env.DATABASE_URL;
+if (!url) {
+ throw new Error("DATABASE_URL is not set. SingleStore Helios requires a valid TLS connection string.");
+}
+const pool = mysql.createPool({
+ uri: url,
+ waitForConnections: true,
+ connectionLimit: 10,
+ maxIdle: 10,
+ queueLimit: 0,
+ enableKeepAlive: true,
+}); 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { singlestoreTable, varchar, bigint, boolean } from "drizzle-orm/singlestore-core"; | ||
|
||
export const todo = singlestoreTable("todo", { | ||
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(), | ||
text: varchar("text", { length: 255 }).notNull(), | ||
completed: boolean("completed").default(false).notNull(), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not force Helios when database='singlestore' — conflicts with PR objective to allow 'none'.
The PR explicitly allows a basic/self-hosted 'none' option. This block prohibits it by erroring when dbSetup==='none'. Remove this constraint.
📝 Committable suggestion
🤖 Prompt for AI Agents