<commit_before>
import {Task, Migration, TaskType} from './migration';
import {Commit} from './git';

export interface TableRow {
    id: number;
    name: string;
    type: TaskType;
    commit: string;
    head: string;
    applied_at: Date;
}

export abstract class DbAdapter {

    public abstract init(): Promise<void>;
    public abstract getLastMigrationTask(): Promise<Task>;
    public abstract logMigrationTask(task: Task): Promise<void>;
    public abstract checkIfTaskCanExecute(task: Task): Promise<void>;

    protected rowToTask(row: TableRow): Task {
        const task = new Task({
            id: row['id'],<commit_msg>move adapter creation to adapter<commit_after>
import {Task, Migration, TaskType} from './migration';
import {PostgresAdapter} from './adapters/postgres';
import {Commit} from './git';
import {parse} from 'url';

export interface TableRow {
    id: number;
    name: string;
    type: TaskType;
    commit: string;
    head: string;
    applied_at: Date;
}

export abstract class DbAdapter {

    public abstract init(): Promise<void>;
    public abstract getLastMigrationTask(): Promise<Task>;
    public abstract logMigrationTask(task: Task): Promise<void>;
    public abstract checkIfTaskCanExecute(task: Task): Promise<void>;

    static getFromUrl(url: string): DbAdapter {
        const dialect = parse(url).protocol;
        switch (dialect) {
            case 'postgres:': return new PostgresAdapter(url, require(process.cwd() + '/node_modules/pg'));
            case null: throw new Error('Invalid connection URL ' + url);
            default: throw new Error('Unssuported dialect ' + dialect);
        }
    }

    protected rowToTask(row: TableRow): Task {
        const task = new Task({
            id: row['id'],
{'fraction_non_alphanumeric': 0.11798071469086784, 'fraction_numerical': 0.0, 'mean_word_length': 3.443324937027708, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6293089', 'n_tokens_mistral': 495, 'n_tokens_neox': 487, 'n_words': 157}