<commit_before>namespace :db do
  desc "Run database migrations"
  task :migrate, :env do |cmd, args|
    env = args[:env] || "development"
    Rake::Task['environment'].invoke(env)

    require 'sequel/extensions/migration'
    Sequel::Migrator.apply(Sequel::Model.db, "./db/migrate")
    puts "Migrated to the latest"
  end

  desc "Rollback the database"
  task :rollback, :env do |cmd, args|
    env = args[:env] || "development"
    Rake::Task['environment'].invoke(env)

    require 'sequel/extensions/migration'
    Sequel::Migrator.apply(Sequel::Model.db, "./db/migrate", -1)
    puts "Rolled back."
  end

  desc "Nuke the database (drop all tables)"
  task :nuke, :env do |cmd, args|
    env = args[:env] || "development"
    Rake::Task['environment'].invoke(env)
    Sequel::Model.db.tables.each do |table|
      Sequel::Model.db.run("DROP TABLE #{table}")
    end
    puts "Nuked database"
  end

  desc "Reset the database"
  task :reset, [:env] => [:nuke, :migrate]

  desc "Create the database"
  task :create, :env do |cmd, args|
    require "uri"
    require "sequel"
    uri = URI.join(ENV["DATABASE_URL"], "/").to_s
    db = Sequel.connect(uri)
    name = URI.parse(ENV["DATABASE_URL"]).path[1..-1]
    db.run(%{CREATE DATABASE "#{name}"})
    puts "Database created"
  end

  desc "Drop the database"
  task :drop, :env do |cmd, args|
    require "uri"
    require "sequel"
    uri = URI.join(ENV["DATABASE_URL"], "/").to_s
    db = Sequel.connect(uri)
    name = URI.parse(ENV["DATABASE_URL"]).path[1..-1]
    db.run(%{DROP DATABASE IF EXISTS "#{name}"})
    puts "Database dropped"
  end

  namespace :schema do
    desc "Load the database schema"
    task :load, :env do |cmd, args|
      env = args[:env] || "development"
      Rake::Task['environment'].invoke(env)
      schema = File.read("./db/schema.sql")
      Sequel::Model.db.run(schema)
      puts "Loaded schema"
    end

    desc "Dump the database schema"
    task :dump, :env do |cmd, args|
      `pg_dump -i -s -x -O -f ./db/schema.sql #{ENV["DATABASE_URL"]}`
      puts "Dumped schema"
    end
  end

  desc "Setup the database"
  task :setup, [:env] => [:drop, :create, "schema:load"]
end
<commit_msg>normalize db access.<commit_after>namespace :db do
  desc "Run database migrations"
  task :migrate, :env do |cmd, args|
    env = args[:env] || "development"
    Rake::Task['environment'].invoke(env)

    require 'sequel/extensions/migration'
    Sequel::Migrator.apply(Sequel::Model.db, "./db/migrate")
    puts "Migrated to the latest"
  end

  desc "Rollback the database"
  task :rollback, :env do |cmd, args|
    env = args[:env] || "development"
    Rake::Task['environment'].invoke(env)

    require 'sequel/extensions/migration'
    Sequel::Migrator.apply(Sequel::Model.db, "./db/migrate", -1)
    puts "Rolled back."
  end

  desc "Nuke the database (drop all tables)"
  task :nuke, :env do |cmd, args|
    env = args[:env] || "development"
    Rake::Task['environment'].invoke(env)
    Sequel::Model.db.tables.each do |table|
      Sequel::Model.db.run(%{DROP TABLE "#{table}"})
    end
    puts "Nuked database"
  end

  desc "Reset the database"
  task :reset, [:env] => [:nuke, :migrate]

  desc "Create the database"
  task :create, :env do |cmd, args|
    require "uri"
    require "sequel"
    uri = URI.join(ENV["DATABASE_URL"], "/").to_s
    db = Sequel.connect(uri)
    name = URI.parse(ENV["DATABASE_URL"]).path[1..-1]
    db.run(%{CREATE DATABASE "#{name}"})
    puts "Database created"
  end

  desc "Drop the database"
  task :drop, :env do |cmd, args|
    require "uri"
    require "sequel"
    uri = URI.join(ENV["DATABASE_URL"], "/").to_s
    db = Sequel.connect(uri)
    name = URI.parse(ENV["DATABASE_URL"]).path[1..-1]
    db.run(%{DROP DATABASE IF EXISTS "#{name}"})
    puts "Database dropped"
  end

  namespace :schema do
    desc "Load the database schema"
    task :load, :env do |cmd, args|
      env = args[:env] || "development"
      Rake::Task['environment'].invoke(env)
      schema = File.read("./db/schema.sql")
      Sequel::Model.db.run(schema)
      puts "Loaded schema"
    end

    desc "Dump the database schema"
    task :dump, :env do |cmd, args|
      `pg_dump -i -s -x -O -f ./db/schema.sql #{ENV["DATABASE_URL"]}`
      puts "Dumped schema"
    end
  end

  desc "Setup the database"
  task :setup, [:env] => [:drop, :create, "schema:load"]
end

{'fraction_non_alphanumeric': 0.16492027334851936, 'fraction_numerical': 0.002277904328018223, 'mean_word_length': 3.181904761904762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7202612', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1577, 'n_words': 412}