<commit_before>package database

import (
	"database/sql"
	"github.com/crockeo/personalwebsite/config"
	_ "github.com/lib/pq"
	_ "github.com/mattn/go-sqlite3"
	"os"
)

// Opening the production database connection
func openPro(url string) (*sql.DB, error) {
	return sql.Open("postgres", url)
}

// Opening the dev database connection
func openDev(pat string) (*sql.DB, error) {
	return sql.Open("sqlite3", pat)
}

// Opening the default database
func OpenDefaultDatabase() (*sql.DB, error) {
	url := os.Getenv("DATABASE_URL")

	if url == "" {
		return openDev(config.DbLoc)
	} else {
		return openPro(url)
	}
}

// Creating the database schema
func CreateDatabaseSchema(db *sql.DB) error {
	_, err := db.Exec("CREATE TABLE IF NOT EXISTS auth (id SERIAL, username TEXT NOT NULL, password TEXT NOT NULL)")

	if err != nil {
		return err
	}

	rows, err := db.Query("SELECT * FROM auth")

	if err != nil {
		rows.Close()
		return err
	} else if !rows.Next() {
		_, err = db.Exec("INSERT INTO auth(username, password) values('admin', 'password')")

		if err != nil {
			return err
		}
	} else {
		rows.Close()
	}

	_, err = db.Exec("CREATE TABLE IF NOT EXISTS posts (id SERIAL, title TEXT NOT NULL, author TEXT NOT NULL, body TEXT NOT NULL, written TEXT NOT NULL)")

	if err != nil {
		return err<commit_msg>Revert "Changed the ids from 'INTEGER NOT NULL PRIMARY KEY' to 'SERIAL'"<commit_after>package database

import (
	"database/sql"
	"github.com/crockeo/personalwebsite/config"
	_ "github.com/lib/pq"
	_ "github.com/mattn/go-sqlite3"
	"os"
)

// Opening the production database connection
func openPro(url string) (*sql.DB, error) {
	return sql.Open("postgres", url)
}

// Opening the dev database connection
func openDev(pat string) (*sql.DB, error) {
	return sql.Open("sqlite3", pat)
}

// Opening the default database
func OpenDefaultDatabase() (*sql.DB, error) {
	url := os.Getenv("DATABASE_URL")

	if url == "" {
		return openDev(config.DbLoc)
	} else {
		return openPro(url)
	}
}

// Creating the database schema
func CreateDatabaseSchema(db *sql.DB) error {
	_, err := db.Exec("CREATE TABLE IF NOT EXISTS auth (id INTEGER NOT NULL PRIMARY KEY, username TEXT NOT NULL, password TEXT NOT NULL)")

	if err != nil {
		return err
	}

	rows, err := db.Query("SELECT * FROM auth")

	if err != nil {
		rows.Close()
		return err
	} else if !rows.Next() {
		_, err = db.Exec("INSERT INTO auth(username, password) values('<PASSWORD>', 'password')")

		if err != nil {
			return err
		}
	} else {
		rows.Close()
	}

	_, err = db.Exec("CREATE TABLE IF NOT EXISTS posts (id INTEGER NOT NULL PRIMARY KEY, title TEXT NOT NULL, author TEXT NOT NULL, body TEXT NOT NULL, written TEXT NOT NULL)")

	if err != nil {
		return err
{'fraction_non_alphanumeric': 0.1348563006632277, 'fraction_numerical': 0.0014738393515106854, 'mean_word_length': 3.7799295774647885, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1315468', 'n_tokens_mistral': 974, 'n_tokens_neox': 911, 'n_words': 296}