Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

use pnpm

Fendy Heryanto1561e0f8bd8d
diff --git a/CLAUDE.md b/CLAUDE.md
index fe82067f7b..29b7ec6918 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -36,7 +36,7 @@ nocodb-sdk β†’ nocodb (backend) β†’ nc-gui (frontend)
Start with migration or SDK type changes when a feature needs them. If schema evolves during the PR, update the same migration file β€” **1 migration per PR max**.
-The format of migration file is `nc_YYYYMMDDHHmm_{title}`, where `nc_` is the prefix, followed by date timestamp, followed by title. Use bash command `echo nc_$(date +%Y%m%d%H%M)_` to generate the prefix for migration file, `touch packages/nocodb/src/meta/migrations/v0/nc_$(date +%Y%m%d%H%M)_add_my_feature.ts` for example will create a migration file titled `add_my_feature`.
+Use `pnpm migration:add table my feature` to create migration `nc_YYYYMMDDHHmm_table_my_feature.ts`.
After SDK changes, rebuild SDK before backend or frontend: `cd packages/nocodb-sdk && pnpm run build:ee`
diff --git a/scripts/addMigration.js b/scripts/addMigration.js
new file mode 100644
index 0000000000..6fc3c68b5b
--- /dev/null
+++ b/scripts/addMigration.js
@@ -0,0 +1,86 @@
+/**
+ * Migration file generator
+ *
+ * Usage:
+ * pnpm migration:add add my feature
+ * node scripts/addMigration.js add my feature
+ *
+ * Output:
+ * Creates: packages/nocodb/src/meta/migrations/v0/nc_YYYYMMDDHHmm_add_my_feature.ts
+ */
+
+const fs = require('fs');
+const path = require('path');
+
+const migrationPath = path.join(__dirname, '../packages/nocodb/src/meta/migrations/v0');
+
+const toSnakeCase = (str) => {
+ return str
+ .trim()
+ .replace(/\s+/g, '_')
+ .toLowerCase();
+};
+
+const generateTimestamp = () => {
+ const now = new Date();
+ const pad = (n) => String(n).padStart(2, '0');
+
+ return (
+ now.getUTCFullYear() +
+ pad(now.getUTCMonth() + 1) +
+ pad(now.getUTCDate()) +
+ pad(now.getUTCHours()) +
+ pad(now.getUTCMinutes())
+ );
+};
+
+const getMigrationTemplate = () => {
+ return `import type { Knex } from 'knex';
+import { MetaTable } from '~/meta/meta.service';
+
+const up = async (knex: Knex) => {
+ // Add your migration logic here
+};
+
+const down = async (knex: Knex) => {
+ // Add your rollback logic here
+};
+
+export { up, down };
+`;
+};
+
+const createMigration = (title) => {
+ const timestamp = generateTimestamp();
+ const snakeTitle = toSnakeCase(title);
+ const filename = `nc_${timestamp}_${snakeTitle}.ts`;
+ const filepath = path.join(migrationPath, filename);
+
+ // Create the migration file
+ fs.writeFileSync(filepath, getMigrationTemplate(), 'utf8');
+
+ console.log(`βœ… Created migration: ${filename}`);
+ console.log(`πŸ“‚ Location: ${filepath}`);
+
+ return filepath;
+};
+
+// Main execution
+const args = process.argv.slice(2);
+
+if (args.length === 0) {
+ console.error('❌ Error: Migration title is required\n');
+ console.log('Usage: node addMigration <Title>');
+ console.log('Example: node addMigration Add My Feature');
+ console.log(' β†’ generates nc_YYYYMMDDHHmm_add_my_feature.ts\n');
+ process.exit(1);
+}
+
+const title = args.join(' ');
+
+try {
+ createMigration(title);
+} catch (error) {
+ console.error('❌ Error creating migration:', error.message);
+ process.exit(1);
+}
\ No newline at end of file