github.com/Ali-iotechsys/sqlboiler/v4@v4.0.0-20221208124957-6aec9a5f1f71/testdata/psql_test_schema.sql (about)

     1  CREATE EXTENSION IF NOT EXISTS citext;
     2  
     3  CREATE TYPE workday AS ENUM('monday', 'tuesday', 'wednesday', 'thursday', 'friday');
     4  CREATE TYPE faceyface AS ENUM('angry', 'hungry', 'bitter');
     5  CREATE TYPE "UserRole" AS ENUM ('SUPER_ADMIN', 'BILLING_ADMIN', 'READ_ONLY_ADMIN', 'USER');
     6  
     7  CREATE TABLE event_one (
     8    id     serial PRIMARY KEY NOT NULL,
     9    name   VARCHAR(255),
    10    day    workday NOT NULL
    11  );
    12  
    13  CREATE TABLE event_two (
    14    id     serial PRIMARY KEY NOT NULL,
    15    name   VARCHAR(255),
    16    day    workday NOT NULL
    17  );
    18  
    19  CREATE TABLE event_three (
    20    id     serial PRIMARY KEY NOT NULL,
    21    name   VARCHAR(255),
    22    day    workday NOT NULL,
    23    face   faceyface NOT NULL,
    24    thing  workday NULL,
    25    stuff  faceyface NULL
    26  );
    27  
    28  CREATE TABLE facey (
    29    id serial PRIMARY KEY NOT NULL,
    30    name VARCHAR(255),
    31    face faceyface NOT NULL
    32  );
    33  
    34  CREATE TABLE magic (
    35    id       serial PRIMARY KEY NOT NULL,
    36    id_two   serial NOT NULL,
    37    id_three serial,
    38  
    39    bool_zero   bool,
    40    bool_one    bool NULL,
    41    bool_two    bool NOT NULL,
    42    bool_three  bool NULL DEFAULT FALSE,
    43    bool_four   bool NULL DEFAULT TRUE,
    44    bool_five   bool NOT NULL DEFAULT FALSE,
    45    bool_six    bool NOT NULL DEFAULT TRUE,
    46  
    47    string_zero   VARCHAR(1),
    48    string_one    VARCHAR(1) NULL,
    49    string_two    VARCHAR(1) NOT NULL,
    50    string_three  VARCHAR(1) NULL DEFAULT 'a',
    51    string_four   VARCHAR(1) NOT NULL DEFAULT 'b',
    52    string_five   VARCHAR(1000),
    53    string_six    VARCHAR(1000) NULL,
    54    string_seven  VARCHAR(1000) NOT NULL,
    55    string_eight  VARCHAR(1000) NULL DEFAULT 'abcdefgh',
    56    string_nine   VARCHAR(1000) NOT NULL DEFAULT 'abcdefgh',
    57    string_ten    VARCHAR(1000) NULL DEFAULT '',
    58    string_eleven VARCHAR(1000) NOT NULL DEFAULT '',
    59  
    60    nonbyte_zero   CHAR(1),
    61    nonbyte_one    CHAR(1) NULL,
    62    nonbyte_two    CHAR(1) NOT NULL,
    63    nonbyte_three  CHAR(1) NULL DEFAULT 'a',
    64    nonbyte_four   CHAR(1) NOT NULL DEFAULT 'b',
    65    nonbyte_five   CHAR(1000),
    66    nonbyte_six    CHAR(1000) NULL,
    67    nonbyte_seven  CHAR(1000) NOT NULL,
    68    nonbyte_eight  CHAR(1000) NULL DEFAULT 'a',
    69    nonbyte_nine   CHAR(1000) NOT NULL DEFAULT 'b',
    70  
    71    byte_zero   "char",
    72    byte_one    "char" NULL,
    73    byte_two    "char" NULL DEFAULT 'a',
    74    byte_three  "char" NOT NULL,
    75    byte_four   "char" NOT NULL DEFAULT 'b',
    76  
    77    big_int_zero  bigint,
    78    big_int_one   bigint NULL,
    79    big_int_two   bigint NOT NULL,
    80    big_int_three bigint NULL DEFAULT 111111,
    81    big_int_four  bigint NOT NULL DEFAULT 222222,
    82    big_int_five  bigint NULL DEFAULT 0,
    83    big_int_six   bigint NOT NULL DEFAULT 0,
    84  
    85    int_zero  int,
    86    int_one   int NULL,
    87    int_two   int NOT NULL,
    88    int_three int NULL DEFAULT 333333,
    89    int_four  int NOT NULL DEFAULT 444444,
    90    int_five  int NULL DEFAULT 0,
    91    int_six   int NOT NULL DEFAULT 0,
    92  
    93    float_zero  decimal,
    94    float_one   numeric,
    95    float_two   numeric(2,1),
    96    float_three numeric(2,1),
    97    float_four  numeric(2,1) NULL,
    98    float_five  numeric(2,1) NOT NULL,
    99    float_six   numeric(2,1) NULL DEFAULT 1.1,
   100    float_seven numeric(2,1) NOT NULL DEFAULT 1.1,
   101    float_eight numeric(2,1) NULL DEFAULT 0.0,
   102    float_nine  numeric(2,1) NULL DEFAULT 0.0,
   103  
   104    bytea_zero  bytea,
   105    bytea_one   bytea NULL,
   106    bytea_two   bytea NOT NULL,
   107    bytea_three bytea NOT NULL DEFAULT 'a',
   108    bytea_four  bytea NULL DEFAULT 'b',
   109    bytea_five  bytea NOT NULL DEFAULT 'abcdefghabcdefghabcdefgh',
   110    bytea_six   bytea NULL DEFAULT 'hgfedcbahgfedcbahgfedcba',
   111    bytea_seven bytea NOT NULL DEFAULT '',
   112    bytea_eight bytea NOT NULL DEFAULT '',
   113  
   114    time_zero      timestamp,
   115    time_one       date,
   116    time_two       timestamp NULL DEFAULT NULL,
   117    time_three     timestamp NULL,
   118    time_four      timestamp NOT NULL,
   119    time_five      timestamp NULL DEFAULT '1999-01-08 04:05:06.789',
   120    time_six       timestamp NULL DEFAULT '1999-01-08 04:05:06.789 -8:00',
   121    time_seven     timestamp NULL DEFAULT 'January 8 04:05:06 1999 PST',
   122    time_eight     timestamp NOT NULL DEFAULT '1999-01-08 04:05:06.789',
   123    time_nine      timestamp NOT NULL DEFAULT '1999-01-08 04:05:06.789 -8:00',
   124    time_ten       timestamp NOT NULL DEFAULT 'January 8 04:05:06 1999 PST',
   125    time_eleven    date NULL,
   126    time_twelve    date NOT NULL,
   127    time_thirteen  date NULL DEFAULT '1999-01-08',
   128    time_fourteen  date NULL DEFAULT 'January 8, 1999',
   129    time_fifteen   date NULL DEFAULT '19990108',
   130    time_sixteen   date NOT NULL DEFAULT '1999-01-08',
   131    time_seventeen date NOT NULL DEFAULT 'January 8, 1999',
   132    time_eighteen  date NOT NULL DEFAULT '19990108',
   133  
   134    uuid_zero  uuid,
   135    uuid_one   uuid NULL,
   136    uuid_two   uuid NULL DEFAULT NULL,
   137    uuid_three uuid NOT NULL,
   138    uuid_four  uuid NULL DEFAULT '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
   139    uuid_five  uuid NOT NULL DEFAULT '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
   140  
   141    strange_one   integer DEFAULT '5'::integer,
   142    strange_two   varchar(1000) DEFAULT 5::varchar,
   143    strange_three timestamp without time zone default (now() at time zone 'utc'),
   144    strange_four  timestamp with time zone default (now() at time zone 'utc'),
   145    strange_five  interval NOT NULL DEFAULT '21 days',
   146    strange_six   interval NULL DEFAULT '23 hours',
   147  
   148    aa  json NULL,
   149    bb  json NOT NULL,
   150    cc  jsonb NULL,
   151    dd  jsonb NOT NULL,
   152    ee  box NULL,
   153    ff  box NOT NULL,
   154    gg  cidr NULL,
   155    hh  cidr NOT NULL,
   156    ii  circle NULL,
   157    jj  circle NOT NULL,
   158    kk  double precision NULL,
   159    ll  double precision NOT NULL,
   160    mm  inet NULL,
   161    nn  inet NOT NULL,
   162    oo  line NULL,
   163    pp  line NOT NULL,
   164    qq  lseg NULL,
   165    rr  lseg NOT NULL,
   166    ss  macaddr NULL,
   167    tt  macaddr NOT NULL,
   168    uu  money NULL,
   169    vv  money NOT NULL,
   170    ww  path NULL,
   171    xx  path NOT NULL,
   172    yy  pg_lsn NULL,
   173    zz  pg_lsn NOT NULL,
   174    aaa point NULL,
   175    bbb point NOT NULL,
   176    ccc polygon NULL,
   177    ddd polygon NOT NULL,
   178    eee tsquery NULL,
   179    fff tsquery NOT NULL,
   180    ggg tsvector NULL,
   181    hhh tsvector NOT NULL,
   182    iii txid_snapshot NULL,
   183    jjj txid_snapshot NOT NULL,
   184    kkk xml NULL,
   185    lll xml NOT NULL,
   186    mmm citext NULL,
   187    nnn citext NOT NULL
   188  );
   189  
   190  create table owner (
   191    id    serial primary key not null,
   192    name  varchar(255) not null
   193  );
   194  
   195  create table cats (
   196    id       serial primary key not null,
   197    name     varchar(255) not null,
   198    owner_id int references owner (id)
   199  );
   200  
   201  create table toys (
   202    id    serial primary key not null,
   203    name  varchar(255) not null
   204  );
   205  
   206  create table cat_toys (
   207    cat_id int not null references cats (id),
   208    toy_id int not null references toys (id),
   209    primary key (cat_id, toy_id)
   210  );
   211  
   212  create table dog_toys (
   213    dog_id int not null,
   214    toy_id int not null,
   215    primary key (dog_id, toy_id)
   216  );
   217  
   218  create table dragon_toys (
   219    dragon_id uuid,
   220    toy_id    uuid,
   221    primary key (dragon_id, toy_id)
   222  );
   223  
   224  create table spider_toys (
   225    spider_id uuid,
   226    name      character varying,
   227    primary key (spider_id)
   228  );
   229  
   230  create table pals (
   231    pal character varying,
   232    name character varying,
   233    primary key (pal)
   234  );
   235  
   236  create table friend (
   237    friend character varying,
   238    name character varying,
   239    primary key (friend)
   240  );
   241  
   242  create table bro (
   243    bros character varying,
   244    name character varying,
   245    primary key (bros)
   246  );
   247  
   248  create table enemies (
   249    enemies character varying,
   250    name character varying,
   251    primary key (enemies)
   252  );
   253  
   254  create table chocolate (
   255    dog varchar(100) primary key
   256  );
   257  
   258  create table waffles (
   259    cat varchar(100) primary key
   260  );
   261  
   262  create table fun_arrays (
   263    id serial,
   264    fun_one integer[] null,
   265    fun_two integer[] not null,
   266    fun_three boolean[] null,
   267    fun_four boolean[] not null,
   268    fun_five varchar[] null,
   269    fun_six varchar[] not null,
   270    fun_seven decimal[] null,
   271    fun_eight decimal[] not null,
   272    fun_nine bytea[] null,
   273    fun_ten bytea[] not null,
   274    fun_eleven jsonb[] null,
   275    fun_twelve jsonb[] not null,
   276    fun_thirteen json[] null,
   277    fun_fourteen json[] not null,
   278    primary key (id)
   279  );
   280  
   281  create table tigers (
   282    id    bytea primary key,
   283    name  bytea null
   284  );
   285  
   286  create table elephants (
   287    id        bytea primary key,
   288    name      bytea not null,
   289    tiger_id  bytea null unique,
   290    foreign key (tiger_id) references tigers (id)
   291  );
   292  
   293  create table wolves (
   294    id        bytea primary key,
   295    name      bytea not null,
   296    tiger_id  bytea not null unique,
   297    foreign key (tiger_id) references tigers (id)
   298  );
   299  
   300  create table ants (
   301    id        bytea primary key,
   302    name      bytea not null,
   303    tiger_id  bytea not null,
   304    foreign key (tiger_id) references tigers (id)
   305  );
   306  
   307  create table worms (
   308    id        bytea primary key,
   309    name      bytea not null,
   310    tiger_id  bytea null,
   311    foreign key (tiger_id) references tigers (id)
   312  );
   313  
   314  create table addresses (
   315    id bytea primary key,
   316    name bytea null
   317  );
   318  
   319  create table houses (
   320    id bytea primary key,
   321    name bytea not null,
   322    address_id bytea not null unique,
   323    foreign key (address_id) references addresses (id)
   324  );
   325  
   326  create table byte_pilots (
   327    id   bytea primary key not null,
   328    name character varying
   329  );
   330  
   331  create table byte_airports (
   332    id   bytea primary key not null,
   333    name character varying
   334  );
   335  
   336  create table byte_languages (
   337    id   bytea primary key not null,
   338    name character varying
   339  );
   340  
   341  create table byte_jets (
   342    id              bytea primary key not null,
   343    name            character varying,
   344    byte_pilot_id   bytea unique,
   345    byte_airport_id bytea,
   346  
   347    foreign key (byte_pilot_id) references byte_pilots (id),
   348    foreign key (byte_airport_id) references byte_airports (id)
   349  );
   350  
   351  create table byte_pilot_languages (
   352    byte_pilot_id    bytea not null,
   353    byte_language_id bytea not null,
   354  
   355    primary key (byte_pilot_id, byte_language_id),
   356    foreign key (byte_pilot_id) references byte_pilots (id),
   357    foreign key (byte_language_id) references byte_languages (id)
   358  );
   359  
   360  create table cars (
   361    id integer not null,
   362    name text,
   363    primary key (id)
   364  );
   365  
   366  create table car_cars (
   367    car_id integer not null,
   368    awesome_car_id integer not null,
   369    relation text not null,
   370    primary key (car_id, awesome_car_id),
   371    foreign key (car_id) references cars(id),
   372    foreign key (awesome_car_id) references cars(id)
   373  );
   374  
   375  create table trucks (
   376    id integer not null,
   377    parent_id integer,
   378    name text,
   379    primary key (id),
   380    foreign key (parent_id) references trucks(id)
   381  );
   382  
   383  CREATE TABLE race (
   384      id integer PRIMARY KEY NOT NULL,
   385      race_date timestamp,
   386      track text
   387  );
   388  
   389  CREATE TABLE race_results (
   390      id integer PRIMARY KEY NOT NULL,
   391      race_id integer,
   392      name text,
   393      foreign key (race_id) references race(id)
   394  );
   395  
   396  CREATE TABLE race_result_scratchings (
   397      id integer PRIMARY KEY NOT NULL,
   398      results_id integer NOT NULL,
   399      name text NOT NULL,
   400      foreign key (results_id) references race_results(id)
   401  );
   402  
   403  CREATE TABLE pilots (
   404    id integer NOT NULL,
   405    name text NOT NULL
   406  );
   407  
   408  ALTER TABLE pilots ADD CONSTRAINT pilot_pkey PRIMARY KEY (id);
   409  
   410  CREATE TABLE jets (
   411    id integer NOT NULL,
   412    pilot_id integer NOT NULL,
   413    age integer NOT NULL,
   414    name text NOT NULL,
   415    color text NOT NULL
   416  );
   417  
   418  ALTER TABLE jets ADD CONSTRAINT jet_pkey PRIMARY KEY (id);
   419  -- The following fkey remains poorly named to avoid regressions related to psql naming
   420  ALTER TABLE jets ADD CONSTRAINT pilots_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id);
   421  
   422  CREATE TABLE languages (
   423    id integer NOT NULL,
   424    language text NOT NULL
   425  );
   426  
   427  ALTER TABLE languages ADD CONSTRAINT language_pkey PRIMARY KEY (id);
   428  
   429  -- Join table
   430  CREATE TABLE pilot_languages (
   431    pilot_id integer NOT NULL,
   432    language_id integer NOT NULL
   433  );
   434  
   435  -- Composite primary key
   436  ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_pkey PRIMARY KEY (pilot_id, language_id);
   437  -- The following fkey remains poorly named to avoid regressions related to psql naming
   438  ALTER TABLE pilot_languages ADD CONSTRAINT pilots_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id);
   439  ALTER TABLE pilot_languages ADD CONSTRAINT languages_fkey FOREIGN KEY (language_id) REFERENCES languages(id);
   440  
   441  -- Previously the generated code had a naming clash when a table was called 'updates'
   442  CREATE TABLE updates (
   443      id integer PRIMARY KEY NOT NULL
   444  );
   445  
   446  -- Create table that has a name with an uppercase letter and columns with uppercase letters
   447  CREATE TABLE "User" (
   448      "id" UUID NOT NULL,
   449      "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
   450      "updatedAt" TIMESTAMP(3) NOT NULL,
   451      "userId" VARCHAR(127) NOT NULL,
   452      "role" "UserRole" NOT NULL DEFAULT E'USER',
   453      "tenantId" UUID NOT NULL,
   454      "clientId" UUID,
   455  
   456      PRIMARY KEY ("id")
   457  );