Skip to content

Commit

Permalink
rewrite init.sql for each docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
apeng-singlestore committed Aug 29, 2024
1 parent db3e4b5 commit 976129d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions integration-tests/tests/singlestore/singlestore-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ import type { Equal } from '~/utils.ts';

import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const initSqlPath = path.resolve(__dirname, 'test/init.sql');

type TestSingleStoreDB = SingleStoreDatabase<any, any>;

Expand Down Expand Up @@ -192,17 +190,26 @@ const citiesMySchemaTable = mySchema.table('cities', {
name: text('name').notNull(),
});



let singlestoreContainer: Docker.Container;
export async function createDockerDB(): Promise<{ connectionString: string; container: Docker.Container }> {
const docker = new Docker();
const port = await getPort({ port: 3306 });
const image = 'ghcr.io/singlestore-labs/singlestoredb-dev:latest';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const initSqlPath = path.resolve(__dirname, 'test/init.sql');
const initSqlContent = `CREATE DATABASE drizzle;`;
fs.writeFileSync(initSqlPath, initSqlContent, { encoding: 'utf8' });

const pullStream = await docker.pull(image);
await new Promise((resolve, reject) =>
docker.modem.followProgress(pullStream, (err) => (err ? reject(err) : resolve(err)))
);


singlestoreContainer = await docker.createContainer({
Image: image,
Env: ['ROOT_PASSWORD=singlestore'],
Expand All @@ -217,10 +224,10 @@ export async function createDockerDB(): Promise<{ connectionString: string; cont
});

await singlestoreContainer.start();
await new Promise((resolve) => setTimeout(resolve, 5000));
await new Promise((resolve) => setTimeout(resolve, 7000));

return {
connectionString: `singlestore://root:singlestore@127.0.0.1:${port}/drizzle`,
connectionString: `singlestore://root:singlestore@localhost:${port}/drizzle`,
container: singlestoreContainer,
};
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/singlestore/test/init.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE database drizzle;
CREATE DATABASE drizzle;

0 comments on commit 976129d

Please sign in to comment.