github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/schema/encoding/integration_test.go (about)

     1  // Copyright 2022 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package encoding_test
    16  
    17  import (
    18  	"context"
    19  	"strings"
    20  	"testing"
    21  
    22  	"github.com/stretchr/testify/assert"
    23  	"github.com/stretchr/testify/require"
    24  
    25  	"github.com/dolthub/dolt/go/cmd/dolt/commands/engine"
    26  	"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
    27  	"github.com/dolthub/dolt/go/libraries/doltcore/schema"
    28  	"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
    29  	"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil"
    30  	"github.com/dolthub/dolt/go/store/chunks"
    31  	"github.com/dolthub/dolt/go/store/types"
    32  )
    33  
    34  func TestSchemaSerializationIntegration(t *testing.T) {
    35  	for i := range integrationTests {
    36  		s := integrationTests[i].schema
    37  		t.Run(getTestName(s), func(t *testing.T) {
    38  			sch := parseSchemaString(t, s)
    39  			t.Run("noms", func(t *testing.T) {
    40  				testSchemaSerializationNoms(t, sch)
    41  			})
    42  			t.Run("flatbuffers", func(t *testing.T) {
    43  				testSchemaSerializationFlatbuffers(t, sch)
    44  			})
    45  		})
    46  	}
    47  }
    48  
    49  func testSchemaSerializationNoms(t *testing.T, sch schema.Schema) {
    50  	ctx := context.Background()
    51  	nbf := types.Format_Default
    52  	vrw := getTestVRW(nbf)
    53  	v, err := encoding.MarshalSchema(ctx, vrw, sch)
    54  	require.NoError(t, err)
    55  	s, err := encoding.UnmarshalSchema(ctx, nbf, v)
    56  	require.NoError(t, err)
    57  	assert.Equal(t, sch, s)
    58  }
    59  
    60  func testSchemaSerializationFlatbuffers(t *testing.T, sch schema.Schema) {
    61  	ctx := context.Background()
    62  	nbf := types.Format_Default
    63  	vrw := getTestVRW(nbf)
    64  	v, err := encoding.SerializeSchema(ctx, vrw, sch)
    65  	require.NoError(t, err)
    66  	s, err := encoding.DeserializeSchema(ctx, nbf, v)
    67  	require.NoError(t, err)
    68  	assert.Equal(t, sch, s)
    69  }
    70  
    71  func parseSchemaString(t *testing.T, s string) schema.Schema {
    72  	ctx := context.Background()
    73  	dEnv := dtestutils.CreateTestEnv()
    74  	defer dEnv.DoltDB.Close()
    75  	root, err := dEnv.WorkingRoot(ctx)
    76  	require.NoError(t, err)
    77  	eng, db, err := engine.NewSqlEngineForEnv(ctx, dEnv)
    78  	require.NoError(t, err)
    79  	sqlCtx, err := eng.NewDefaultContext(ctx)
    80  	require.NoError(t, err)
    81  	sqlCtx.SetCurrentDatabase(db)
    82  	_, sch, err := sqlutil.ParseCreateTableStatement(sqlCtx, root, eng.GetUnderlyingEngine(), s)
    83  	require.NoError(t, err)
    84  	return sch
    85  }
    86  
    87  func getTestVRW(nbf *types.NomsBinFormat) types.ValueReadWriter {
    88  	ts := &chunks.TestStorage{}
    89  	cs := ts.NewViewWithFormat(nbf.VersionString())
    90  	return types.NewValueStore(cs)
    91  }
    92  
    93  func getTestName(sch string) string {
    94  	n := sch[:strings.Index(sch, "(")]
    95  	return strings.TrimSpace(n)
    96  }
    97  
    98  var integrationTests = []struct {
    99  	schema string
   100  }{
   101  	{
   102  		schema: "CREATE table t1 (" +
   103  			"a INTEGER PRIMARY KEY check (a > 3)," +
   104  			"b INTEGER check (b > a));",
   105  	},
   106  	{
   107  		schema: "create table t2 (" +
   108  			"pk int," +
   109  			"c1 int," +
   110  			"CHECK (c1 > 3)," +
   111  			"PRIMARY KEY (pk));",
   112  	},
   113  
   114  	// SHAQ
   115  	{
   116  		schema: "CREATE TABLE `league_seasons` (" +
   117  			"`league_id` int NOT NULL," +
   118  			"`season_id` int NOT NULL," +
   119  			"PRIMARY KEY (`league_id`,`season_id`)" +
   120  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   121  	},
   122  	{
   123  		schema: "CREATE TABLE `leagues` (" +
   124  			"`league_id` int NOT NULL," +
   125  			"`name` varchar(100)," +
   126  			"PRIMARY KEY (`league_id`)" +
   127  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   128  	},
   129  	{
   130  		schema: "CREATE TABLE `player_season_stat_totals` (" +
   131  			"`player_id` int NOT NULL," +
   132  			"`team_id` int NOT NULL," +
   133  			"`season_id` int NOT NULL," +
   134  			"`minutes` int," +
   135  			"`games_started` int," +
   136  			"`games_played` int," +
   137  			"`2pm` int," +
   138  			"`2pa` int," +
   139  			"`3pm` int," +
   140  			"`3pa` int," +
   141  			"`ftm` int," +
   142  			"`fta` int," +
   143  			"`ast` int," +
   144  			"`stl` int," +
   145  			"`blk` int," +
   146  			"`tov` int," +
   147  			"`pts` int," +
   148  			"`orb` int," +
   149  			"`drb` int," +
   150  			"`trb` int," +
   151  			"`pf` int," +
   152  			"`season_type_id` int NOT NULL," +
   153  			"`league_id` int NOT NULL DEFAULT 0," +
   154  			"PRIMARY KEY (`player_id`,`team_id`,`season_id`,`season_type_id`,`league_id`)" +
   155  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   156  	},
   157  	{
   158  		schema: "CREATE TABLE `players` (" +
   159  			"`player_id` int NOT NULL," +
   160  			"`nba_player_id` int," +
   161  			"`date_of_birth` date," +
   162  			"`first_name` varchar(255)," +
   163  			"`last_name` varchar(255)," +
   164  			"`height_inches` int," +
   165  			"`weight_lb` int," +
   166  			"PRIMARY KEY (`player_id`)," +
   167  			"KEY `idx_last` (`first_name`,`last_name`)" +
   168  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   169  	},
   170  	{
   171  		schema: "CREATE TABLE `season_types` (" +
   172  			"`season_type_id` int NOT NULL," +
   173  			"`description` varchar(55)," +
   174  			"PRIMARY KEY (`season_type_id`)" +
   175  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   176  	},
   177  	{
   178  		schema: "CREATE TABLE `team_seasons` (" +
   179  			"`team_id` int NOT NULL," +
   180  			"`league_id` int NOT NULL," +
   181  			"`season_id` int NOT NULL," +
   182  			"`prefix` varchar(100)," +
   183  			"`nickname` varchar(100)," +
   184  			"`abbreviation` varchar(100)," +
   185  			"`city` varchar(100)," +
   186  			"`state` varchar(100)," +
   187  			"`country` varchar(100)," +
   188  			"PRIMARY KEY (`team_id`,`league_id`,`season_id`)" +
   189  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   190  	},
   191  	{
   192  		schema: "CREATE TABLE `teams` (" +
   193  			"`team_id` int NOT NULL," +
   194  			"`league_id` int NOT NULL," +
   195  			"`full_name` varchar(100)," +
   196  			"PRIMARY KEY (`team_id`,`league_id`)" +
   197  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   198  	},
   199  
   200  	// Sakila
   201  	{
   202  		schema: "CREATE TABLE `actor` (" +
   203  			"`actor_id` smallint unsigned NOT NULL AUTO_INCREMENT," +
   204  			"`first_name` varchar(45) NOT NULL," +
   205  			"`last_name` varchar(45) NOT NULL," +
   206  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   207  			"PRIMARY KEY (`actor_id`)," +
   208  			"KEY `idx_actor_last_name` (`last_name`)" +
   209  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   210  	},
   211  	{
   212  		schema: "CREATE TABLE `address` (" +
   213  			"`address_id` smallint unsigned NOT NULL AUTO_INCREMENT," +
   214  			"`address` varchar(50) NOT NULL," +
   215  			"`address2` varchar(50) DEFAULT NULL," +
   216  			"`district` varchar(20) NOT NULL," +
   217  			"`city_id` smallint unsigned NOT NULL," +
   218  			"`postal_code` varchar(10) DEFAULT NULL," +
   219  			"`phone` varchar(20) NOT NULL," +
   220  			"`location` geometry NOT NULL," +
   221  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   222  			"PRIMARY KEY (`address_id`)," +
   223  			"KEY `idx_fk_city_id` (`city_id`)," +
   224  			"CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   225  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   226  	},
   227  	{
   228  		schema: "CREATE TABLE `all_types` (" +
   229  			"`pk` int NOT NULL," +
   230  			"`v1` binary(1) DEFAULT NULL," +
   231  			"`v2` bigint DEFAULT NULL," +
   232  			"`v3` bit(1) DEFAULT NULL," +
   233  			"`v4` blob," +
   234  			"`v5` char(1) DEFAULT NULL," +
   235  			"`v6` date DEFAULT NULL," +
   236  			"`v7` datetime DEFAULT NULL," +
   237  			"`v8` decimal(5,2) DEFAULT NULL," +
   238  			"`v9` double DEFAULT NULL," +
   239  			"`v10` enum('s','m','l') DEFAULT NULL," +
   240  			"`v11` float DEFAULT NULL," +
   241  			"`v12` geometry DEFAULT NULL," +
   242  			"`v13` int DEFAULT NULL," +
   243  			"`v14` json DEFAULT NULL," +
   244  			"`v15` linestring DEFAULT NULL," +
   245  			"`v16` longblob," +
   246  			"`v17` longtext," +
   247  			"`v18` mediumblob," +
   248  			"`v19` mediumint DEFAULT NULL," +
   249  			"`v20` mediumtext," +
   250  			"`v21` point DEFAULT NULL," +
   251  			"`v22` polygon DEFAULT NULL," +
   252  			"`v23` set('one','two') DEFAULT NULL," +
   253  			"`v24` smallint DEFAULT NULL," +
   254  			"`v25` text," +
   255  			"`v26` time(6) DEFAULT NULL," +
   256  			"`v27` timestamp DEFAULT NULL," +
   257  			"`v28` tinyblob," +
   258  			"`v29` tinyint DEFAULT NULL," +
   259  			"`v30` tinytext," +
   260  			"`v31` varchar(255) DEFAULT NULL," +
   261  			"`v32` varbinary(255) DEFAULT NULL," +
   262  			"`v33` year DEFAULT NULL," +
   263  			"`v34` datetime(6) DEFAULT current_timestamp(6)," +
   264  			"`v35` timestamp(6) DEFAULT now(6)," +
   265  			"`v36` datetime(3) DEFAULT current_timestamp(3)," +
   266  			"`v37` timestamp(3) DEFAULT now(3)," +
   267  			"PRIMARY KEY (`pk`)" +
   268  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   269  	},
   270  	{
   271  		schema: "CREATE TABLE `category` (" +
   272  			"`category_id` tinyint unsigned NOT NULL AUTO_INCREMENT," +
   273  			"`name` varchar(25) NOT NULL," +
   274  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   275  			"PRIMARY KEY (`category_id`)" +
   276  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   277  	},
   278  	{
   279  		schema: "CREATE TABLE `city` (" +
   280  			"`city_id` smallint unsigned NOT NULL AUTO_INCREMENT," +
   281  			"`city` varchar(50) NOT NULL," +
   282  			"`country_id` smallint unsigned NOT NULL," +
   283  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   284  			"PRIMARY KEY (`city_id`)," +
   285  			"KEY `idx_fk_country_id` (`country_id`)," +
   286  			"CONSTRAINT `fk_city_country` FOREIGN KEY (`country_id`) REFERENCES `country` (`country_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   287  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   288  	},
   289  	{
   290  		schema: "CREATE TABLE `country` (" +
   291  			"`country_id` smallint unsigned NOT NULL AUTO_INCREMENT," +
   292  			"`country` varchar(50) NOT NULL," +
   293  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   294  			"PRIMARY KEY (`country_id`)" +
   295  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   296  	},
   297  	{
   298  		schema: "CREATE TABLE `customer` (" +
   299  			"`customer_id` smallint unsigned NOT NULL AUTO_INCREMENT," +
   300  			"`store_id` tinyint unsigned NOT NULL," +
   301  			"`first_name` varchar(45) NOT NULL," +
   302  			"`last_name` varchar(45) NOT NULL," +
   303  			"`email` varchar(50) DEFAULT NULL," +
   304  			"`address_id` smallint unsigned NOT NULL," +
   305  			"`active` tinyint NOT NULL DEFAULT \"1\"," +
   306  			"`create_date` datetime NOT NULL," +
   307  			"`last_update` timestamp DEFAULT CURRENT_TIMESTAMP()," +
   308  			"PRIMARY KEY (`customer_id`)," +
   309  			"KEY `idx_fk_address_id` (`address_id`)," +
   310  			"KEY `idx_fk_store_id` (`store_id`)," +
   311  			"KEY `idx_last_name` (`last_name`)," +
   312  			"CONSTRAINT `fk_customer_address` FOREIGN KEY (`address_id`) REFERENCES `address` (`address_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   313  			"CONSTRAINT `fk_customer_store` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   314  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   315  	},
   316  	{
   317  		schema: "CREATE TABLE `film` (" +
   318  			"`film_id` smallint unsigned NOT NULL AUTO_INCREMENT," +
   319  			"`title` varchar(128) NOT NULL," +
   320  			"`description` text," +
   321  			"`release_year` year DEFAULT NULL," +
   322  			"`language_id` tinyint unsigned NOT NULL," +
   323  			"`original_language_id` tinyint unsigned DEFAULT NULL," +
   324  			"`rental_duration` tinyint unsigned NOT NULL DEFAULT \"3\"," +
   325  			"`rental_rate` decimal(4,2) NOT NULL DEFAULT \"4.99\"," +
   326  			"`length` smallint unsigned DEFAULT NULL," +
   327  			"`replacement_cost` decimal(5,2) NOT NULL DEFAULT \"19.99\"," +
   328  			"`rating` enum('g','pg','pg-13','r','nc-17') DEFAULT \"G\"," +
   329  			"`special_features` set('trailers','commentaries','deleted scenes','behind the scenes') DEFAULT NULL," +
   330  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   331  			"PRIMARY KEY (`film_id`)," +
   332  			"KEY `idx_fk_language_id` (`language_id`)," +
   333  			"KEY `idx_fk_original_language_id` (`original_language_id`)," +
   334  			"KEY `idx_title` (`title`)," +
   335  			"CONSTRAINT `fk_film_language` FOREIGN KEY (`language_id`) REFERENCES `language` (`language_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   336  			"CONSTRAINT `fk_film_language_original` FOREIGN KEY (`original_language_id`) REFERENCES `language` (`language_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   337  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   338  	},
   339  	{
   340  		schema: "CREATE TABLE `film_actor` (" +
   341  			"`actor_id` smallint unsigned NOT NULL," +
   342  			"`film_id` smallint unsigned NOT NULL," +
   343  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   344  			"PRIMARY KEY (`actor_id`,`film_id`)," +
   345  			"KEY `idx_fk_film_id` (`film_id`)," +
   346  			"CONSTRAINT `fk_film_actor_actor` FOREIGN KEY (`actor_id`) REFERENCES `actor` (`actor_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   347  			"CONSTRAINT `fk_film_actor_film` FOREIGN KEY (`film_id`) REFERENCES `film` (`film_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   348  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   349  	},
   350  	{
   351  		schema: "CREATE TABLE `film_category` (" +
   352  			"`film_id` smallint unsigned NOT NULL," +
   353  			"`category_id` tinyint unsigned NOT NULL," +
   354  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   355  			"PRIMARY KEY (`film_id`,`category_id`)," +
   356  			"KEY `fk_film_category_category` (`category_id`)," +
   357  			"CONSTRAINT `fk_film_category_category` FOREIGN KEY (`category_id`) REFERENCES `category` (`category_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   358  			"CONSTRAINT `fk_film_category_film` FOREIGN KEY (`film_id`) REFERENCES `film` (`film_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   359  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   360  	},
   361  	{
   362  		schema: "CREATE TABLE `film_text` (" +
   363  			"`film_id` smallint NOT NULL," +
   364  			"`title` varchar(255) NOT NULL," +
   365  			"`description` text," +
   366  			"PRIMARY KEY (`film_id`)" +
   367  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   368  	},
   369  	{
   370  		schema: "CREATE TABLE `inventory` (" +
   371  			"`inventory_id` mediumint unsigned NOT NULL AUTO_INCREMENT," +
   372  			"`film_id` smallint unsigned NOT NULL," +
   373  			"`store_id` tinyint unsigned NOT NULL," +
   374  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   375  			"PRIMARY KEY (`inventory_id`)," +
   376  			"KEY `idx_fk_film_id` (`film_id`)," +
   377  			"KEY `idx_store_id_film_id` (`store_id`,`film_id`)," +
   378  			"CONSTRAINT `fk_inventory_film` FOREIGN KEY (`film_id`) REFERENCES `film` (`film_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   379  			"CONSTRAINT `fk_inventory_store` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   380  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   381  	},
   382  	{
   383  		schema: "CREATE TABLE `language` (" +
   384  			"`language_id` tinyint unsigned NOT NULL AUTO_INCREMENT," +
   385  			"`name` char(20) NOT NULL," +
   386  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   387  			"PRIMARY KEY (`language_id`)" +
   388  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   389  	},
   390  	{
   391  		schema: "CREATE TABLE `payment` (" +
   392  			"`payment_id` smallint unsigned NOT NULL AUTO_INCREMENT," +
   393  			"`customer_id` smallint unsigned NOT NULL," +
   394  			"`staff_id` tinyint unsigned NOT NULL," +
   395  			"`rental_id` int DEFAULT NULL," +
   396  			"`amount` decimal(5,2) NOT NULL," +
   397  			"`payment_date` datetime NOT NULL," +
   398  			"`last_update` timestamp DEFAULT CURRENT_TIMESTAMP()," +
   399  			"PRIMARY KEY (`payment_id`)," +
   400  			"KEY `fk_payment_rental` (`rental_id`)," +
   401  			"KEY `idx_fk_customer_id` (`customer_id`)," +
   402  			"KEY `idx_fk_staff_id` (`staff_id`)," +
   403  			"CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   404  			"CONSTRAINT `fk_payment_rental` FOREIGN KEY (`rental_id`) REFERENCES `rental` (`rental_id`) ON DELETE SET NULL ON UPDATE CASCADE," +
   405  			"CONSTRAINT `fk_payment_staff` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`staff_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   406  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   407  	},
   408  	{
   409  		schema: "CREATE TABLE `rental` (" +
   410  			"`rental_id` int NOT NULL AUTO_INCREMENT," +
   411  			"`rental_date` datetime NOT NULL," +
   412  			"`inventory_id` mediumint unsigned NOT NULL," +
   413  			"`customer_id` smallint unsigned NOT NULL," +
   414  			"`return_date` datetime DEFAULT NULL," +
   415  			"`staff_id` tinyint unsigned NOT NULL," +
   416  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   417  			"PRIMARY KEY (`rental_id`)," +
   418  			"KEY `idx_fk_customer_id` (`customer_id`)," +
   419  			"KEY `idx_fk_inventory_id` (`inventory_id`)," +
   420  			"KEY `idx_fk_staff_id` (`staff_id`)," +
   421  			"UNIQUE KEY `rental_date` (`rental_date`,`inventory_id`,`customer_id`)," +
   422  			"CONSTRAINT `fk_rental_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   423  			"CONSTRAINT `fk_rental_inventory` FOREIGN KEY (`inventory_id`) REFERENCES `inventory` (`inventory_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   424  			"CONSTRAINT `fk_rental_staff` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`staff_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   425  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   426  	},
   427  	{
   428  		schema: "CREATE TABLE `staff` (" +
   429  			"`staff_id` tinyint unsigned NOT NULL AUTO_INCREMENT," +
   430  			"`first_name` varchar(45) NOT NULL," +
   431  			"`last_name` varchar(45) NOT NULL," +
   432  			"`address_id` smallint unsigned NOT NULL," +
   433  			"`picture` blob," +
   434  			"`email` varchar(50) DEFAULT NULL," +
   435  			"`store_id` tinyint unsigned NOT NULL," +
   436  			"`active` tinyint NOT NULL DEFAULT \"1\"," +
   437  			"`username` varchar(16) NOT NULL," +
   438  			"`password` varchar(40) collate utf8mb4_bin DEFAULT NULL," +
   439  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   440  			"PRIMARY KEY (`staff_id`)," +
   441  			"KEY `idx_fk_address_id` (`address_id`)," +
   442  			"KEY `idx_fk_store_id` (`store_id`)," +
   443  			"CONSTRAINT `fk_staff_address` FOREIGN KEY (`address_id`) REFERENCES `address` (`address_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   444  			"CONSTRAINT `fk_staff_store` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   445  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   446  	},
   447  	{
   448  		schema: "CREATE TABLE `store` (" +
   449  			"`store_id` tinyint unsigned NOT NULL AUTO_INCREMENT," +
   450  			"`manager_staff_id` tinyint unsigned NOT NULL," +
   451  			"`address_id` smallint unsigned NOT NULL," +
   452  			"`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()," +
   453  			"PRIMARY KEY (`store_id`)," +
   454  			"KEY `idx_fk_address_id` (`address_id`)," +
   455  			"UNIQUE KEY `idx_unique_manager` (`manager_staff_id`)," +
   456  			"CONSTRAINT `fk_store_address` FOREIGN KEY (`address_id`) REFERENCES `address` (`address_id`) ON DELETE RESTRICT ON UPDATE CASCADE," +
   457  			"CONSTRAINT `fk_store_staff` FOREIGN KEY (`manager_staff_id`) REFERENCES `staff` (`staff_id`) ON DELETE RESTRICT ON UPDATE CASCADE" +
   458  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   459  	},
   460  	{
   461  		schema: "CREATE TABLE `types_default` (" +
   462  			"`pk` int NOT NULL," +
   463  			"`v1` binary(1) DEFAULT \"1\"," +
   464  			"`v2` bigint DEFAULT \"1\"," +
   465  			"`v3` bit(2) DEFAULT 2," +
   466  			"`v4` blob DEFAULT (\"abc\")," +
   467  			"`v5` char(1) DEFAULT \"i\"," +
   468  			"`v6` date DEFAULT \"2022-02-22\"," +
   469  			"`v7` datetime DEFAULT \"2022-02-22 22:22:22\"," +
   470  			"`v8` decimal(5,2) DEFAULT \"999.99\"," +
   471  			"`v9` double DEFAULT \"1.1\"," +
   472  			"`v10` enum('s','m','l') DEFAULT \"s\"," +
   473  			"`v11` float DEFAULT \"1.1\"," +
   474  			"`v12` geometry DEFAULT (POINT(1, 2))," +
   475  			"`v13` int DEFAULT \"1\"," +
   476  			"`v14` json DEFAULT (JSON_OBJECT(\"a\", 1))," +
   477  			"`v15` linestring DEFAULT (LINESTRING(POINT(0, 0),POINT(1, 2)))," +
   478  			"`v16` longblob DEFAULT (\"abc\")," +
   479  			"`v17` longtext DEFAULT (\"abc\")," +
   480  			"`v18` mediumblob DEFAULT (\"abc\")," +
   481  			"`v19` mediumint DEFAULT \"1\"," +
   482  			"`v20` mediumtext DEFAULT (\"abc\")," +
   483  			"`v21` point DEFAULT (POINT(1, 2))," +
   484  			"`v22` polygon DEFAULT (POLYGON(LINESTRING(POINT(0, 0),POINT(8, 0),POINT(12, 9),POINT(0, 9),POINT(0, 0))))," +
   485  			"`v23` set('one','two') DEFAULT \"one\"," +
   486  			"`v24` smallint DEFAULT \"1\"," +
   487  			"`v25` text DEFAULT (\"abc\")," +
   488  			"`v26` time(6) DEFAULT \"11:59:59.000000\"," +
   489  			"`v27` timestamp DEFAULT \"2021-01-19 03:14:07\"," +
   490  			"`v28` tinyblob DEFAULT (\"abc\")," +
   491  			"`v29` tinyint DEFAULT \"1\"," +
   492  			"`v30` tinytext DEFAULT (\"abc\")," +
   493  			"`v31` varchar(255) DEFAULT \"varchar value\"," +
   494  			"`v32` varbinary(255) DEFAULT \"11111\"," +
   495  			"`v33` year DEFAULT \"2018\"," +
   496  			"PRIMARY KEY (`pk`)" +
   497  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   498  	},
   499  	{
   500  		schema: "CREATE TABLE `collations` (" +
   501  			"`pk` int NOT NULL," +
   502  			"`v5` char(1) collate utf8mb3_esperanto_ci DEFAULT \"i\"," +
   503  			"`v17` longtext collate utf8mb3_esperanto_ci DEFAULT (\"abc\")," +
   504  			"`v20` mediumtext collate utf8mb3_esperanto_ci DEFAULT (\"abc\")," +
   505  			"`v25` text collate utf8mb3_esperanto_ci DEFAULT (\"abc\")," +
   506  			"`v31` varchar(255) collate utf8mb3_esperanto_ci DEFAULT \"varchar value\"," +
   507  			"PRIMARY KEY (`pk`)" +
   508  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
   509  	},
   510  	{
   511  		schema: "CREATE TABLE `collations2` (" +
   512  			"`pk` int NOT NULL," +
   513  			"`v5` char(1) DEFAULT \"i\"," +
   514  			"`v17` longtext DEFAULT (\"abc\")," +
   515  			"`v20` mediumtext collate utf8mb4_es_0900_ai_ci DEFAULT (\"abc\")," +
   516  			"`v25` text collate utf8mb4_0900_bin DEFAULT (\"abc\")," +
   517  			"`v31` varchar(255) collate utf8mb4_hungarian_ci DEFAULT \"varchar value\"," +
   518  			"PRIMARY KEY (`pk`)" +
   519  			") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_esperanto_ci;",
   520  	},
   521  }