<commit_before>#!/usr/bin/env ruby
require 'sequel'
require 'fileutils'

## WARNING: THIS DELETES ALL DATA AND RE-CREATES (empty) TABLES!

if ENV['AHS_DATABASE_TYPE'] == 'mysql'
    _DB = Sequel.connect('mysql://ahuser:password@localhost/ahtest') 
    _DB.run "drop database if exists ahtest;"
    _DB.run "create database ahtest;"
    _DB.run "use ahtest;"
elsif ENV['AHS_DATABASE_TYPE'] == 'sqlite'
    dbfile = "#{File.dirname(__FILE__)}/ahtest.sqlite3"
    if File.exists? dbfile
        FileUtils.rm dbfile
    end
    #DB = Sequel.sqlite(dbfile) 
end

require_relative './db_init'


# FIXME - add null/not null, unique etc., constraints throughout

DB.create_table! :resources do
    primary_key :id
    String :ah_id, {:null => false, :unique => true}

    String :title
    String :dataprovider
    String :species
    Integer :taxonomyid
    String :genome
    String :description
    TrueClass :coordinate_1_based
    String :maintainer
    Integer :status_id
    Integer :location_prefix_id
    Integer :recipe_id
    String :rdataversion
    Date :rdatadateadded # FIXME add index here!

 end

# add users table, info about who uploaded what and when,
#... permissions.

DB.create_table! :rdatapaths do
    primary_key :id
    String :rdatapath
    String :rdataclass
    Integer :rdatasize
    String :derivedmd5
    Date :rdatalastmodifieddate
    foreign_key :resource_id, :resources
end

DB.create_table! :input_sources do
    primary_key :id
    String :sourcefile
    String :sourcesize # integer?
    String :sourceurl<commit_msg>changed derivedmd5 to rdatamd5 for consistency<commit_after>#!/usr/bin/env ruby
require 'sequel'
require 'fileutils'

## WARNING: THIS DELETES ALL DATA AND RE-CREATES (empty) TABLES!

if ENV['AHS_DATABASE_TYPE'] == 'mysql'
    _DB = Sequel.connect('mysql://ahuser:password@localhost/ahtest') 
    _DB.run "drop database if exists ahtest;"
    _DB.run "create database ahtest;"
    _DB.run "use ahtest;"
elsif ENV['AHS_DATABASE_TYPE'] == 'sqlite'
    dbfile = "#{File.dirname(__FILE__)}/ahtest.sqlite3"
    if File.exists? dbfile
        FileUtils.rm dbfile
    end
    #DB = Sequel.sqlite(dbfile) 
end

require_relative './db_init'


# FIXME - add null/not null, unique etc., constraints throughout

DB.create_table! :resources do
    primary_key :id
    String :ah_id, {:null => false, :unique => true}

    String :title
    String :dataprovider
    String :species
    Integer :taxonomyid
    String :genome
    String :description
    TrueClass :coordinate_1_based
    String :maintainer
    Integer :status_id
    Integer :location_prefix_id
    Integer :recipe_id
    String :rdataversion
    Date :rdatadateadded # FIXME add index here!

 end

# add users table, info about who uploaded what and when,
#... permissions.

DB.create_table! :rdatapaths do
    primary_key :id
    String :rdatapath
    String :rdataclass
    Integer :rdatasize
    String :rdatamd5
    Date :rdatalastmodifieddate
    foreign_key :resource_id, :resources
end

DB.create_table! :input_sources do
    primary_key :id
    String :sourcefile
    String :sourcesize # integer?
    String :sourceurl
{'fraction_non_alphanumeric': 0.09395973154362416, 'fraction_numerical': 0.002556727388942154, 'mean_word_length': 3.5494186046511627, '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': '5064360', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1033, 'n_words': 286}