mysql - SQL: Application cross-db maintain only one generic schema -


i have application based on mysql schema based on innodb (with constraints...) co-workers need import schema, export schema in sql files.

for example:

drop table if exists `admins`; create table `admins` (   `id` smallint(5) unsigned not null auto_increment,   `username` varchar(45) not null,   `password` varchar(45) not null,   `email` varchar(45) default null,   `creation_date` datetime not null,   `close_date` datetime default null,   `close_reason` varchar(45) default null,   primary key (`id`) ) engine=innodb  default charset=utf8 auto_increment=4 ; 

now, have cross-db application, so:

  • i tried import previous sql files in postgresql, didn't work, sql files mysql-related (for example use of ` character...)
  • i tried export schema mysqldump , compatibility mode "--compatible=ansi" goal: have generic sql file compatible major sgbd. didn't work: postgresql returns error synthax

compatible=ansi returns:

drop table if exists "admins"; /*!40101 set @saved_cs_client     = @@character_set_client */; /*!40101 set character_set_client = utf8 */; create table "admins" (   "id" smallint(5) unsigned not null auto_increment,   "username" varchar(45) not null,   "password" varchar(45) not null,   "email" varchar(45) default null,   "creation_date" datetime not null,   "close_date" datetime default null,   "close_reason" varchar(45) default null,   primary key ("id") ); /*!40101 set character_set_client = @saved_cs_client */; 

i tried export compatibility=postgresql:

drop table if exists "admins"; /*!40101 set @saved_cs_client     = @@character_set_client */; /*!40101 set character_set_client = utf8 */; create table "admins" (   "id" smallint(5) unsigned not null,   "username" varchar(45) not null,   "password" varchar(45) not null,   "email" varchar(45) default null,   "creation_date" datetime not null,   "close_date" datetime default null,   "close_reason" varchar(45) default null,   primary key ("id") ); /*!40101 set character_set_client = @saved_cs_client */; 

but didn't work...

i know there tools convert mysql schema postgresql schema isn't goal...

my question: possible have 1 sql file compatible mysql, postgresql, sqlite... , don't maintain sql file each sgbd ?

thank you

my question: possible have 1 sql file compatible mysql, postgresql, sqlite... , don't maintain sql file each sgbd ?

not raw sql, unless wish use pathetic subset of databases' supported features.

selects , dml in sql can moderately portable, ddl hopeless nightmare total basics. you'll want abstraction tool generates sql you, handling database specific differences in sequences/generated keys, type naming, constraints, index creation, etc.

as 1 example, lets @ auto-incrementing values / sequences, used synthetic keys:

  • mysql: integer auto_increment
  • postgresql: serial (shorthand sequence)
  • ms-sql: int identity(1,1)
  • oracle (below 12c): no direct support, use sequence.
  • oracle (12c , above): number generated default on null identity

.. , that's common task of generated key. lots of other fun differences exist. example, mysql has tinyint , unsigned int. postgresql not. postgresql has bool , has bit(n) bitfields, range-types, postgis types, etc etc etc other dbs don't have. things that're shared, quirks abound - specifying "4 byte signed integer" across dbs isn't trivial.

one option liquibase i've heard things about. people instead use orm manage ddl generation instead - though tend use, again, primitive of database features.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -