#!/usr/pkg/bin/ruby33
# frozen_string_literal: true

require 'bundler/setup'
require 'active_record'
require 'dotenv'
Dotenv.load

# Setup PostgreSQL database
puts 'Setting up PostgreSQL test database...'
ActiveRecord::Base.establish_connection(
  adapter: 'postgresql',
  host: 'localhost',
  port: 5433,
  database: ENV['DB_NAME'],
  username: ENV['DB_USER'],
  password: ENV['DB_PASSWORD']
)

ActiveRecord::Schema.define(version: 1) do
  create_table 'tags', force: true do |t|
    t.string 'name'
  end

  create_table 'tag_audits', id: false, force: true do |t|
    t.string 'tag_name'
  end

  create_table 'labels', id: false, force: true do |t|
    t.string 'name'
  end
end
puts 'PostgreSQL tables created!'

# Setup MySQL database
puts "\nSetting up MySQL test database..."
ActiveRecord::Base.establish_connection(
  adapter: 'mysql2',
  host: '127.0.0.1',
  port: 3366,
  database: ENV['DB_NAME'],
  username: ENV['DB_USER'],
  password: ENV['DB_PASSWORD']
)

ActiveRecord::Schema.define(version: 1) do
  create_table 'mysql_tags', force: true do |t|
    t.string 'name'
  end

  create_table 'mysql_tag_audits', id: false, force: true do |t|
    t.string 'tag_name'
  end

  create_table 'mysql_labels', id: false, force: true do |t|
    t.string 'name'
  end
end
puts 'MySQL tables created!'

puts "\nTest databases setup complete!"
