'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
	async up(queryInterface, Sequelize) {
		await queryInterface.sequelize.transaction(async (transaction) => {
			await queryInterface.addColumn(
				'rides',
				'bus_number',
				{
					type: Sequelize.STRING,
					allowNull: false,
				},
				{ transaction },
			);
			await queryInterface.addColumn(
				'rides',
				'date',
				{
					type: Sequelize.DATEONLY,
					allowNull: false,
				},
				{ transaction },
			);
			await queryInterface.addColumn(
				'rides',
				'onboard_at',
				{
					type: Sequelize.DATE,
					allowNull: false,
				},
				{ transaction },
			);
			await queryInterface.addColumn(
				'rides',
				'offboard_at',
				{
					type: Sequelize.DATE,
					allowNull: true,
				},
				{ transaction },
			);
			await queryInterface.addColumn(
				'rides',
				'driver_route_id',
				{
					type: Sequelize.UUID,
					allowNull: false,
				},
				{ transaction },
			);
			await queryInterface.removeColumn('rides', 'bus_id', { transaction });
		});
	},

	async down(queryInterface, Sequelize) {
		await queryInterface.sequelize.transaction(async (transaction) => {
			await queryInterface.removeColumn('rides', 'bus_number', { transaction });
			await queryInterface.removeColumn('rides', 'date', { transaction });
			await queryInterface.removeColumn('rides', 'onboard_at', { transaction });
			await queryInterface.removeColumn('rides', 'offboard_at', { transaction });
			await queryInterface.removeColumn('rides', 'driver_route_id', { transaction });
			await queryInterface.addColumn(
				'rides',
				'bus_id',
				{
					type: Sequelize.UUID,
					allowNull: false,
				},
				{ transaction },
			);
		});
	},
};
