import Sequelize from '@sequelize/core';
import { SqliteDialect } from '@sequelize/sqlite3';
import { Attachment } from './Attachment';
import { Auth } from './Auth';
import { Bucket } from './Bucket';
import { DBState } from './DBState';
import { Post, PostBucket, addPostScopes } from './Post';
import { PostTag } from './PostTag';
import { Project } from './Project';
import { Tag } from './Tag';
import { User, addUserScopes } from './User';
import { UserPerms, addUserPermsScopes } from './UserPerms';

export * from './APIKey';
export * from './Attachment';
export * from './Auth';
export * from './Bucket';
export * from './DBState';
export * from './Post';
export * from './PostTag';
export * from './Project';
export * from './Tag';
export * from './User';
export * from './UserPerms';

export const sequelize = new Sequelize({
    dialect: SqliteDialect,
    storage: './db/db.sqlite',
    models: [Auth, Attachment, Bucket, DBState, Post, PostBucket, PostTag, Project, Tag, User, UserPerms],
});


export const dbSync = (async ()=> await sequelize.sync())().then(()=>{
    addUserScopes();
    addUserPermsScopes();
    addPostScopes();
});
