MCPcopy Create free account
hub / github.com/Effect-TS/effect / make

Function make

packages/effect/src/unstable/sql/Migrator.ts:100–322  ·  view source on GitHub ↗
({
  dumpSchema = () => Effect.void
}: {
  dumpSchema?: (
    path: string,
    migrationsTable: string
  ) => Effect.Effect<void, MigrationError, RD>
})

Source from the content-addressed store, hash-verified

98 * @since 4.0.0
99 */
100export const make = <RD = never>({
101 dumpSchema = () => Effect.void
102}: {
103 dumpSchema?: (
104 path: string,
105 migrationsTable: string
106 ) => Effect.Effect<void, MigrationError, RD>
107}) =>
108<R2 = never>({
109 loader,
110 schemaDirectory,
111 table = "effect_sql_migrations"
112}: MigratorOptions<R2>): Effect.Effect<
113 ReadonlyArray<readonly [id: number, name: string]>,
114 MigrationError | SqlError,
115 Client.SqlClient | RD | R2
116> =>
117 Effect.gen(function*() {
118 const sql = yield* Client.SqlClient
119
120 const ensureMigrationsTable = sql.onDialectOrElse({
121 mssql: () =>
122 sql`IF OBJECT_ID(N'${sql.literal(table)}', N'U') IS NULL
123 CREATE TABLE ${sql(table)} (
124 migration_id INT NOT NULL PRIMARY KEY,
125 name VARCHAR(255) NOT NULL,
126 created_at DATETIME NOT NULL DEFAULT GETDATE()
127 )`,
128 mysql: () =>
129 sql`CREATE TABLE IF NOT EXISTS ${sql(table)} (
130 migration_id INTEGER UNSIGNED NOT NULL,
131 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
132 name VARCHAR(255) NOT NULL,
133 PRIMARY KEY (migration_id)
134)`,
135 pg: () =>
136 Effect.catch(
137 sql`select ${table}::regclass`,
138 () =>
139 sql`CREATE TABLE ${sql(table)} (
140 migration_id integer primary key,
141 created_at timestamp with time zone not null default now(),
142 name text not null
143)`
144 ),
145 orElse: () =>
146 sql`CREATE TABLE IF NOT EXISTS ${sql(table)} (
147 migration_id integer PRIMARY KEY NOT NULL,
148 created_at datetime NOT NULL DEFAULT current_timestamp,
149 name VARCHAR(255) NOT NULL
150)`
151 })
152
153 const insertMigrations = (
154 rows: ReadonlyArray<[id: number, name: string]>
155 ) =>
156 sql`INSERT INTO ${sql(table)} ${
157 sql.insert(

Callers

nothing calls this directly

Calls 14

pipeFunction · 0.90
loadMigrationFunction · 0.85
insertMigrationsFunction · 0.85
runMigrationFunction · 0.85
dumpSchemaFunction · 0.85
allMethod · 0.80
pushMethod · 0.80
isConstraintConflictFunction · 0.70
forEachMethod · 0.65
pipeMethod · 0.65
toStringMethod · 0.65
StringInterface · 0.50

Tested by

no test coverage detected