terra-sync / cnc

Seamless Database Replication tool
GNU General Public License v3.0
4 stars 2 forks source link

Simplifying the codebase #24

Closed panosfol closed 4 months ago

panosfol commented 5 months ago

Write now in order to implement a new database system, we need to follow these steps:

For the config:

For the database operations:

I was thinking maybe if there was a way to automate some of these steps through a script? (I've seen a script for "code injection" using Ruby). Im not sure if thats applicable on our case but there is a lot of stuff given the struct name and the fields from config, that we can actually automate for multiple database systems. I'm pretty sure all SQL databases will have the same fields for the struct, and maybe many of the NoSQL databases too, we can even automate that.

charmitro commented 5 months ago

Write now in order to implement a new database system, we need to follow these steps: For the config:

  • Create a new struct that holds all the necessary info to connect to the database, and place it in |config.h|
  • Add a new field to struct |config_t| located in |config.h| for the newly created struct
  • Allocate memory for the new struct inside |initialize_config| in |config.c|

This can be fixed.

  • Add to the |ini_parse| in |config.c| all the necessary checks to populate the fields of the struct For the database operations:

Not sure about this, theoretically we can automate this but not sure how at this moment.

  • Add a field to the |db_t| struct in |db.h| that holds a pointer to the struct created in |config.h|

We can make "typedef struct postgres_t" a generic "typedef struct db_fields" since most database will be OK with it.

  • Implement the |connect|, |replicate|, |close| functions for the new database system
  • Make sure all the allocated memory is freed

These two are very custom and I prefer to leave them as they are. We want users to freely implement their own replication logic, apart from the usual one.

I was thinking maybe if there was a way to automate some of these steps through a script? (I've seen a script for "code injection" using Ruby).

No.

Im not sure if thats applicable on our case but there is a lot of stuff given the struct name and the fields from config, that we can actually automate for multiple database systems. I'm pretty sure all SQL databases will have the same fields for the struct, and maybe many of the NoSQL databases too, we can even automate that.

panosfol commented 5 months ago

Write now in order to implement a new database system, we need to follow these steps: For the config: Create a new struct that holds all the necessary info to connect to the database, and place it in |config.h| Add a new field to struct |config_t| located in |config.h| for the newly created struct Allocate memory for the new struct inside |initialize_config| in |config.c| This can* be fixed.

  • Add to the |ini_parse| in |config.c| all the necessary checks to populate the fields of the struct For the database operations: Not sure about this, theoretically we can automate this but not sure how at this moment.
  • Add a field to the |db_t| struct in |db.h| that holds a pointer to the struct created in |config.h| We can make "typedef struct postgres_t" a generic "typedef struct db_fields" since most database will be OK with it.
  • Implement the |connect|, |replicate|, |close| functions for the new database system * Make sure all the allocated memory is freed These two are very custom and I prefer to leave them as they are. We want users to freely implement their own replication logic, apart from the usual one. I was thinking maybe if there was a way to automate some of these steps through a script? (I've seen a script for "code injection" using Ruby). No. Im not sure if thats applicable on our case but there is a lot of stuff given the struct name and the fields from config, that we can actually automate for multiple database systems. I'm pretty sure all SQL databases will have the same fields for the struct, and maybe many of the NoSQL databases too, we can even automate that.

I wasnt looking to automate all of these, some will stay the way they are. But we can simplify some of them.

charmitro commented 4 months ago

Can we close this also? @panosfol

panosfol commented 4 months ago

Yes all the major issues has been addressed.