Skip to content
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

feature: fake migrations for existing tables #6195

Closed
rubiin opened this issue Jun 4, 2020 · 8 comments · Fixed by #8976
Closed

feature: fake migrations for existing tables #6195

rubiin opened this issue Jun 4, 2020 · 8 comments · Fixed by #8976

Comments

@rubiin
Copy link

rubiin commented Jun 4, 2020

Issue type:

[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue

it would be great to fake migrations something like https://docs.djangoproject.com/en/1.11/ref/django-admin/#cmdoption-migrate-fake .

@rubiin
Copy link
Author

rubiin commented Jun 6, 2020

heres a workaround i did

import "reflect-metadata";
import {createConnection, MigrationExecutor} from "typeorm";


createConnection().then(async connection => {
    const mig = new MigrationExecutor(connection);
    await mig.showMigrations();
    const migrations = await mig.getAllMigrations();
    for (let migration of migrations)
    {
        await mig.insertMigration(migration);
    }

}).catch(error => console.log(error));

@rubiin
Copy link
Author

rubiin commented Jun 9, 2020

revised version:

import 'reflect-metadata';
import { createConnection, MigrationExecutor } from 'typeorm';
import config from './config';
import { join } from 'path';

createConnection({
	type: 'postgres',
	host: config.db.host,
	port: config.db.port,
	username: config.db.username,
	password: config.db.password,
	database: config.db.database,
	entities: [join(__dirname, 'entities/*{.ts,.js}')],
	logging: 'all',
	migrationsTableName: 'nest_migration',
	logger: 'advanced-console',
	migrations: [join(__dirname, 'migrations/**/*{.ts,.js}')],
	cli: {
		migrationsDir: join('src', 'migrations'),
	},
})
	.then(async connection => {
		const mig = new MigrationExecutor(connection);
		await connection.manager.query(
			` CREATE TABLE IF NOT EXISTS "nest_migration" ("id" SERIAL NOT NULL, "timestamp" bigint NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_d8a054ea06850edd968e06c00e4" PRIMARY KEY ("id"))`,
		);
		const migrations = await mig.getAllMigrations();

		console.log(migrations);

		for (let migration of migrations) {
			//	await mig.insertMigration(migration);

			await connection.manager.query(
				` INSERT INTO "nest_migration"("timestamp", "name") VALUES ($1, $2) `,
				[migration.timestamp, migration.name],
			);
		}
	})
	.catch(error => console.log(error));

@rubiin
Copy link
Author

rubiin commented Jun 9, 2020

@pleerock can we dosomething like this with the cli. i find it a good addition

@Pipeliner
Copy link

@rubiin was something like this feature implemented?

@rubiin
Copy link
Author

rubiin commented Apr 7, 2022

Sadly no. I have to moveon to MikroOrm due to so many things

@Pipeliner
Copy link

Pipeliner commented Apr 7, 2022 via email

@rubiin rubiin reopened this Apr 7, 2022
@ahmedosama94
Copy link
Contributor

ahmedosama94 commented Apr 21, 2022

@rubiin willing to contribute if no one has already picked this up, please let me know.

@rubiin
Copy link
Author

rubiin commented Apr 21, 2022

@ahmedosama94 You can go ahead. This issue has not been picked up. But make sure they are willing to add it first though

ahmedosama94 added a commit to ahmedosama94/typeorm that referenced this issue May 8, 2022
Added a cli option to fake-run or fake-revert a migration, adding to the
executed migrations table, but not actually running it. This feature is
useful for when migrations are added after the fact or for
interoperability between applications which are desired to each keep
a consistent migration history

Closes: typeorm#6195
ahmedosama94 added a commit to ahmedosama94/typeorm that referenced this issue May 8, 2022
Added a cli option to fake-run or fake-revert a migration, adding to the
executed migrations table, but not actually running it. This feature is
useful for when migrations are added after the fact or for
interoperability between applications which are desired to each keep
a consistent migration history

Closes: typeorm#6195
ahmedosama94 added a commit to ahmedosama94/typeorm that referenced this issue May 8, 2022
Added a cli option to fake-run or fake-revert a migration, adding to the
executed migrations table, but not actually running it. This feature is
useful for when migrations are added after the fact or for
interoperability between applications which are desired to each keep
a consistent migration history

Closes: typeorm#6195
ahmedosama94 added a commit to ahmedosama94/typeorm that referenced this issue May 8, 2022
Added a cli option to fake-run or fake-revert a migration, adding to the
executed migrations table, but not actually running it. This feature is
useful for when migrations are added after the fact or for
interoperability between applications which are desired to each keep
a consistent migration history

Closes: typeorm#6195
AlexMesser added a commit that referenced this issue Aug 25, 2022
* feat: add fake migrations running and reverting

Added a cli option to fake-run or fake-revert a migration, adding to the
executed migrations table, but not actually running it. This feature is
useful for when migrations are added after the fact or for
interoperability between applications which are desired to each keep
a consistent migration history

Closes: #6195

* changed enabled drivers in test

* added docs to the property

* fixed lint issue

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
Co-authored-by: Dmitry Zotov <dmzt08@gmail.com>
nordinh pushed a commit to nordinh/typeorm that referenced this issue Aug 29, 2022
* feat: add fake migrations running and reverting

Added a cli option to fake-run or fake-revert a migration, adding to the
executed migrations table, but not actually running it. This feature is
useful for when migrations are added after the fact or for
interoperability between applications which are desired to each keep
a consistent migration history

Closes: typeorm#6195

* changed enabled drivers in test

* added docs to the property

* fixed lint issue

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
Co-authored-by: Dmitry Zotov <dmzt08@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants