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

Function make

packages/effect/src/sql/Migrator.ts:116–364  ·  view source on GitHub ↗
({
  transformWrites = identity,
  dumpSchema = () => Effect.void
}: {
  transformWrites?: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
  dumpSchema?: (
    path: string,
    migrationsTable: string
  ) => Effect.Effect<void, MigrationError, RD>
})

Source from the content-addressed store, hash-verified

114 * @since 4.0.0
115 */
116export const make = <RD = never>({
117 transformWrites = identity,
118 dumpSchema = () => Effect.void
119}: {
120 transformWrites?: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
121 dumpSchema?: (
122 path: string,
123 migrationsTable: string
124 ) => Effect.Effect<void, MigrationError, RD>
125}) =>
126<R2 = never>({
127 loader,
128 schemaDirectory,
129 table = "effect_sql_migrations"
130}: MigratorOptions<R2>): Effect.Effect<
131 ReadonlyArray<readonly [id: number, name: string]>,
132 MigrationError | SqlError,
133 Client.SqlClient | RD | R2
134> =>
135 Effect.gen(function*() {
136 const sql = yield* Client.SqlClient
137
138 const createMigrationsTable = transformWrites(sql.onDialectOrElse({
139 mssql: () =>
140 sql`IF OBJECT_ID(N'${sql.literal(table)}', N'U') IS NULL
141 CREATE TABLE ${sql(table)} (
142 migration_id INT NOT NULL PRIMARY KEY,
143 name VARCHAR(255) NOT NULL,
144 created_at DATETIME NOT NULL DEFAULT GETDATE()
145 )`,
146 mysql: () =>
147 sql`CREATE TABLE IF NOT EXISTS ${sql(table)} (
148 migration_id INTEGER UNSIGNED NOT NULL,
149 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
150 name VARCHAR(255) NOT NULL,
151 PRIMARY KEY (migration_id)
152)`,
153 clickhouse: () =>
154 // sqlite's `PRIMARY KEY NOT NULL` is a syntax error here
155 sql`CREATE TABLE IF NOT EXISTS ${sql(table)} (
156 migration_id Int32,
157 created_at DateTime DEFAULT now(),
158 name String
159) ENGINE = MergeTree
160ORDER BY migration_id`,
161 pg: () =>
162 sql`CREATE TABLE ${sql(table)} (
163 migration_id integer primary key,
164 created_at timestamp with time zone not null default now(),
165 name text not null
166)`,
167 orElse: () =>
168 sql`CREATE TABLE IF NOT EXISTS ${sql(table)} (
169 migration_id integer PRIMARY KEY NOT NULL,
170 created_at datetime NOT NULL DEFAULT current_timestamp,
171 name VARCHAR(255) NOT NULL
172)`
173 }))

Callers

nothing calls this directly

Calls 15

pipeFunction · 0.90
migrationsTableExistsFunction · 0.85
loadMigrationFunction · 0.85
insertMigrationsFunction · 0.85
runMigrationFunction · 0.85
dumpSchemaFunction · 0.85
literalMethod · 0.80
isConstraintConflictFunction · 0.70
pipeMethod · 0.65
failMethod · 0.65
allMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected