Replies: 2 comments
-
Hi @amrit92, Happy to hear you're enjoying remult. While we are still working on a more robust DB versioning/migration solution, you can use the current functionality configured using the When the For db versioning, until we'll add one built into remult, I use the following code to perform changes as the application evolves: import { Entity, Fields, IdEntity, remult, SqlDatabase } from "remult";
import { recordChanges } from "../app/change-log/change-log";
import { Computer } from "../app/computers/computer";
@Entity(undefined!, {
dbName: "versionInfo"
})
export class VersionInfo extends IdEntity {
@Fields.number()
version: number = 0;
}
export async function versionUpdate() {
let version = async (ver: number, what: () => Promise<void>) => {
let v = await remult.repo(VersionInfo).findFirst();
if (!v) {
v = remult.repo(VersionInfo).create();
v.version = 0;
}
if (v.version <= ver - 1) {
await what();
v.version = ver;
await v.save();
}
};
await version(1, async () => {
for await (const c of await remult.repo(Computer).query()) {
await recordChanges(c, {
forceDate: c.createDate,
forceNew: true
})
}
});
await version(2, async () => {
const db = remult.dataProvider as SqlDatabase;
const computer = remult.repo(Computer).metadata;
const indexColumns = await Promise.all(
[computer.fields.origin, computer.fields.createDate]
.map(c => c.getDbName()))
await db.execute(`create index if not exists computerIndex on ${await computer.getDbName()} (${indexColumns.join(',')})`)
});
}
As for production use, remult is used in production in multiple project. Here is it's source code Remult is used in multiple other projects, some are open source and on Git Hub, and others are on private repos built by commercial companies. |
Beta Was this translation helpful? Give feedback.
-
We've just released version https://github.com/remult/remult/releases/tag/v0.26.0 with a built in solution for db migrations: Check it out |
Beta Was this translation helpful? Give feedback.
-
Would like to start by saying thanks for Remult, its a very simple concept and makes implementation a breeze. I'd like to know how a Database schema version is maintained (Postgres specifically) and if not what are the downsides. From what I've been playing around with, it seems like changes to model are immediately reflected on the database and there's no easy way of rolling back if needed except through code.
Also are there any examples of production usage of Remult? That'd solidify my confidence.
Beta Was this translation helpful? Give feedback.
All reactions