mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(test): update paths and mocks
This commit is contained in:
@@ -1,15 +1,7 @@
|
||||
import { type PostgresJsDatabase, drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
// import { sc } from "@dokploy/schema";
|
||||
import * as schema from "./schema";
|
||||
// schema
|
||||
// import * as schema from "@dokploy/schema";
|
||||
|
||||
// type Schema = typeof schema;
|
||||
|
||||
// type Schema = typeof schema;
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var -- only var works here
|
||||
var db: PostgresJsDatabase<typeof schema> | undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
||||
import postgres from "postgres";
|
||||
// import { drizzle } from "drizzle-orm/postgres-js";
|
||||
// import { migrate } from "drizzle-orm/postgres-js/migrator";
|
||||
// import postgres from "postgres";
|
||||
|
||||
const connectionString = process.env.DATABASE_URL || "";
|
||||
// const connectionString = process.env.DATABASE_URL || "";
|
||||
|
||||
const sql = postgres(connectionString, { max: 1 });
|
||||
const db = drizzle(sql);
|
||||
// const sql = postgres(connectionString, { max: 1 });
|
||||
// const db = drizzle(sql);
|
||||
|
||||
export const migration = async () =>
|
||||
await migrate(db, { migrationsFolder: "drizzle" })
|
||||
.then(() => {
|
||||
console.log("Migration complete");
|
||||
sql.end();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Migration failed", error);
|
||||
})
|
||||
.finally(() => {
|
||||
sql.end();
|
||||
});
|
||||
// export const migration = async () =>
|
||||
// await migrate(db, { migrationsFolder: "drizzle" })
|
||||
// .then(() => {
|
||||
// console.log("Migration complete");
|
||||
// sql.end();
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.log("Migration failed", error);
|
||||
// })
|
||||
// .finally(() => {
|
||||
// sql.end();
|
||||
// });
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
// Credits to Louistiti from Drizzle Discord: https://discord.com/channels/1043890932593987624/1130802621750448160/1143083373535973406
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
// import { sql } from "drizzle-orm";
|
||||
// // Credits to Louistiti from Drizzle Discord: https://discord.com/channels/1043890932593987624/1130802621750448160/1143083373535973406
|
||||
// import { drizzle } from "drizzle-orm/postgres-js";
|
||||
// import postgres from "postgres";
|
||||
|
||||
const connectionString = process.env.DATABASE_URL || "";
|
||||
// const connectionString = process.env.DATABASE_URL || "";
|
||||
|
||||
const pg = postgres(connectionString, { max: 1 });
|
||||
const db = drizzle(pg);
|
||||
// const pg = postgres(connectionString, { max: 1 });
|
||||
// const db = drizzle(pg);
|
||||
|
||||
const clearDb = async (): Promise<void> => {
|
||||
try {
|
||||
const tablesQuery = sql<string>`DROP SCHEMA public CASCADE; CREATE SCHEMA public; DROP schema drizzle CASCADE;`;
|
||||
const tables = await db.execute(tablesQuery);
|
||||
console.log(tables);
|
||||
await pg.end();
|
||||
} catch (error) {
|
||||
console.error("Error to clean database", error);
|
||||
} finally {
|
||||
}
|
||||
};
|
||||
// const clearDb = async (): Promise<void> => {
|
||||
// try {
|
||||
// const tablesQuery = sql<string>`DROP SCHEMA public CASCADE; CREATE SCHEMA public; DROP schema drizzle CASCADE;`;
|
||||
// const tables = await db.execute(tablesQuery);
|
||||
// console.log(tables);
|
||||
// await pg.end();
|
||||
// } catch (error) {
|
||||
// console.error("Error to clean database", error);
|
||||
// } finally {
|
||||
// }
|
||||
// };
|
||||
|
||||
clearDb();
|
||||
// clearDb();
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
import bc from "bcrypt";
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
import { users } from "./schema";
|
||||
// import bc from "bcrypt";
|
||||
// import { drizzle } from "drizzle-orm/postgres-js";
|
||||
// import postgres from "postgres";
|
||||
// import { users } from "./schema";
|
||||
|
||||
const connectionString = process.env.DATABASE_URL || "";
|
||||
// const connectionString = process.env.DATABASE_URL || "";
|
||||
|
||||
const pg = postgres(connectionString, { max: 1 });
|
||||
const db = drizzle(pg);
|
||||
// const pg = postgres(connectionString, { max: 1 });
|
||||
// const db = drizzle(pg);
|
||||
|
||||
function password(txt: string) {
|
||||
return bc.hashSync(txt, 10);
|
||||
}
|
||||
// function password(txt: string) {
|
||||
// return bc.hashSync(txt, 10);
|
||||
// }
|
||||
|
||||
async function seed() {
|
||||
console.log("> Seed:", process.env.DATABASE_PATH, "\n");
|
||||
// async function seed() {
|
||||
// console.log("> Seed:", process.env.DATABASE_PATH, "\n");
|
||||
|
||||
// const authenticationR = await db
|
||||
// .insert(users)
|
||||
// .values([
|
||||
// {
|
||||
// email: "user1@hotmail.com",
|
||||
// password: password("12345671"),
|
||||
// },
|
||||
// ])
|
||||
// .onConflictDoNothing()
|
||||
// .returning();
|
||||
// // const authenticationR = await db
|
||||
// // .insert(users)
|
||||
// // .values([
|
||||
// // {
|
||||
// // email: "user1@hotmail.com",
|
||||
// // password: password("12345671"),
|
||||
// // },
|
||||
// // ])
|
||||
// // .onConflictDoNothing()
|
||||
// // .returning();
|
||||
|
||||
// console.log("\nSemillas Update:", authenticationR.length);
|
||||
}
|
||||
// // console.log("\nSemillas Update:", authenticationR.length);
|
||||
// }
|
||||
|
||||
seed().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
// seed().catch((e) => {
|
||||
// console.error(e);
|
||||
// process.exit(1);
|
||||
// });
|
||||
|
||||
Reference in New Issue
Block a user