--source include/have_s3.inc
--source include/have_sequence.inc

#
# Create unique database for running the tests
#
--source create_database.inc
--disable_warnings
drop table if exists t1,t2;
--enable_warnings

let $datadir=`select @@datadir`;

--echo #
--echo # Test discovery of s3
--echo #

create table t1 (a int, b int) engine=aria select seq as a, seq+10 as b from seq_1_to_10;
alter table t1 engine=s3;

--echo #
--echo # Check discovery by select
--echo #

--remove_file $datadir/$database/t1.frm
flush tables;
select * from t1 limit 1;

--echo #
--echo # Check if changes to .frm is copied to S3
--echo #

alter table t1 change column b c int not null;
flush tables;
--remove_file $datadir/$database/t1.frm
select * from t1 limit 1;

--echo #
--echo # Check if SHOW TABLES finds the S3 tables
--echo #

create table t2 (a int, b int) engine=aria select seq as a, seq+10 as b from seq_1_to_10;
alter table t2 engine=s3;

flush tables;
--remove_file $datadir/$database/t1.frm
--replace_result $database database
SHOW TABLES;
drop table t2;

--echo #
--echo # Check if DROP TABLE works with discovery
--echo #

select count(*) from t1;
flush tables;
--remove_file $datadir/$database/t1.frm
drop table t1;
--replace_result $database database
--error ER_NO_SUCH_TABLE
select count(*), sum(a) from t1;

--echo #
--echo # Check if S3 detects that the .frm is too old
--echo #

create table t1 (a int, b int) engine=aria select seq as a, seq+10 as b from seq_1_to_10;
alter table t1 engine=s3;
--copy_file $datadir/$database/t1.frm $datadir/$database/t1.frm-old
alter table t1 add column c int, engine=s3;
flush tables;
--remove_file $datadir/$database/t1.frm
--copy_file $datadir/$database/t1.frm-old $datadir/$database/t1.frm
--remove_file $datadir/$database/t1.frm-old
select * from t1 limit 1;
flush tables;
--remove_file $datadir/$database/t1.frm
select * from t1 limit 1;
drop table t1;

#
# clean up
#
--source drop_database.inc
