Feature discussion: Auto-sync table fields
See original GitHub issueHi. I just noticed that there are currently no feature which allows us to automatically add new fields to a table. For example, if I have this model
class Project extends Model {
static table = "projects";
static timestamps = true;
static fields = {
id: { primaryKey: true, autoIncrement: true, type: DataTypes.INTEGER },
name: DataTypes.TEXT,
date: DataTypes.DATETIME,
};
static transactions() {
return this.hasMany(Transaction);
}
}
and when I add the newField
field
class Project extends Model {
static table = "projects";
static timestamps = true;
static fields = {
id: { primaryKey: true, autoIncrement: true, type: DataTypes.INTEGER },
name: DataTypes.TEXT,
date: DataTypes.DATETIME,
/* This field */
newField: DataTypes.INTEGER
/* This field */
};
static transactions() {
return this.hasMany(Transaction);
}
}
and then we run
await db.sync();
The newField
doesn’t get automatically added. To add new field, we’ll have to pass { drop: true }
and remove the whole table. Every ORM I’ve come across like GORM (Golang) or JPA (Java) has this auto-add fields feature without dropping the table and I think it’s crucial.
Are there any plans to implement this yet or is someone already working on it? If not, I’d like to try making this feature.
I don’t think this feature is trivial and implementing this can be tricky especially with relationships, so I’ll need lots of feedback as I’m working on this.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:21 (19 by maintainers)
Top Results From Across the Web
Auto Sync with DB for fields with seqeunces..
With AutoSync we wonM-4t have to sync all the fields that have a seqeunce on each import/export of a solution.
Read more >Big SQL Automatic Catalog Synchronization (Part 1
This first blog is an introduction to Auto-Sync, discussing its significance, the problem it addresses and how it can be enabled/disabled. Background Big...
Read more >[Solved] Does Auto Sync need to be On Insert
For the first problem: If the [column] property in your DBML file is set as IsDbGenerated = true then we are specifying that...
Read more >RG Email Sidebar Synchronization Overview
These mapping tables are used to compare the values in matching fields and transfer updated values from email server to Salesforce or vice...
Read more >Deep Dive - Configuring advanced settings for Sage Intacct
If your policy has been connected to Intacct with Auto Sync disabled, ... the approver can be set in the Expensify People table....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, I’ve done some work on my fork vmasdani/denodb. The function is
experimentalAutoMigrate
. I’ve successfully detected missing fields using select field like this:If the field does not exist, it will throw an error and will try to create the missing field/column. (Note the
[object Object]
bug while mapping the primary key, haven’t fixed that yet)I tried an attempt to run an
alter table
query. However I learned that QueryType does not supportalter table
andadd column
yet so I had to add the query type and description here and here.After that, I also noticed that this library uses dex for dialect translation, so It’ll take some time for me to learn how to map
QueryDescription
to dex’s query builder for thealter table
.I haven’t made tests but you can use this code to try the
experimentalAutoMigrate
function with this code:Run with
deno run --allow-all main.ts
I’ll give more updates when I finished integrating
QueryDescription
intodex
. Should I open a PR for this progress, by the way?Guys! Sorry to invited my self to the discussion. I’m so excited to see where this functionality will be go! If you need help, count on me.