Change schema definitions, change qw formatting

- Added `belongs_to` properties for foreign keys
- Added subforums table and restructured database around that
- `qw` formatting was changed (was `qw/ foo bar baz /` in some places, is now `qw(foo bar baz)` everywhere I think)
This commit is contained in:
ngoomie 2023-05-06 00:02:47 -06:00
parent 744c916fde
commit 2ad959ffa8
9 changed files with 81 additions and 36 deletions

View File

@ -1,5 +1,5 @@
--
-- File generated with SQLiteStudio v3.4.4 on Fri. May 5 22:21:17 2023
-- File generated with SQLiteStudio v3.4.4 on Sat. May 6 00:01:26 2023
--
-- Text encoding used: UTF-8
--
@ -8,12 +8,7 @@ BEGIN TRANSACTION;
-- Table: categories
DROP TABLE IF EXISTS categories;
CREATE TABLE IF NOT EXISTS "categories" (
"cat_id" INTEGER NOT NULL UNIQUE,
"cat_name" TEXT,
"cat_desc" TEXT,
PRIMARY KEY("cat_id" AUTOINCREMENT)
);
CREATE TABLE IF NOT EXISTS categories (cat_id INTEGER NOT NULL UNIQUE, cat_name TEXT, PRIMARY KEY (cat_id AUTOINCREMENT));
-- Table: posts
DROP TABLE IF EXISTS posts;
@ -36,9 +31,13 @@ CREATE TABLE IF NOT EXISTS "session" (
PRIMARY KEY("user_id")
);
-- Table: subforums
DROP TABLE IF EXISTS subforums;
CREATE TABLE IF NOT EXISTS subforums (subf_id INTEGER PRIMARY KEY UNIQUE NOT NULL, subf_cat INTEGER REFERENCES categories (cat_id) UNIQUE NOT NULL, subf_name TEXT NOT NULL, subf_desc);
-- Table: threads
DROP TABLE IF EXISTS threads;
CREATE TABLE IF NOT EXISTS threads (thread_id INTEGER NOT NULL, thread_title TEXT NOT NULL, thread_cat INTEGER REFERENCES categories (cat_id), PRIMARY KEY (thread_id AUTOINCREMENT));
CREATE TABLE IF NOT EXISTS threads (thread_id INTEGER NOT NULL, thread_title TEXT NOT NULL, thread_subf INTEGER REFERENCES categories (cat_id), PRIMARY KEY (thread_id AUTOINCREMENT));
-- Table: users
DROP TABLE IF EXISTS users;

View File

@ -32,8 +32,8 @@ sub registration_do ($app) {
# check to make sure username and/or email isn't already in use;
# if not, continue with registration
my $userCheck = $app->schema->resultset('User')->search({username => $username})->single;
my $emailCheck = $app->schema->resultset('User')->search({email => $email})->single;
my $userCheck = $app->schema->resultset('Users')->search({username => $username})->single;
my $emailCheck = $app->schema->resultset('Users')->search({email => $email})->single;
if ( $userCheck || $emailCheck ) {
if ( $userCheck && $emailCheck ) {
# notify user that username and email are both already being used
@ -51,7 +51,7 @@ sub registration_do ($app) {
} else {
$password = $app->pepper . ':' . $password;
my ($hash, $salt) = pass_gen($password);
$app->schema->resultset('User')->create({
$app->schema->resultset('Users')->create({
username => $username,
email => $email,
password => $hash,

View File

@ -3,7 +3,7 @@ use Authen::Passphrase::Argon2;
use Exporter qw(import);
our @EXPORT = qw/ pass_gen /;
our @EXPORT = qw(pass_gen);
sub pass_gen ($) {
my $argon2 = Authen::Passphrase::Argon2->new(

View File

@ -1,20 +1,16 @@
package CharmBoard::Schema::Result::Categories;
use base qw/DBIx::Class::Core/;
use base qw(DBIx::Class::Core);
__PACKAGE__->table('categories');
__PACKAGE__->add_columns(
cat_id => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 1
is_nullable => 0,
},
cat_name => {
data_type => 'text',
is_nullable => 0
},
cat_desc => {
data_type => 'text',
is_nullable => 1
is_nullable => 0,
});
__PACKAGE__->set_primary_key('cat_id');

View File

@ -1,28 +1,38 @@
package CharmBoard::Schema::Result::Posts;
use base qw/DBIx::Class::Core/;
use base qw(DBIx::Class::Core);
__PACKAGE__->table('posts');
__PACKAGE__->add_columns(
post_id => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 0
is_nullable => 0,
},
user_id => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 0
is_nullable => 0,
},
thread_id => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 0
is_nullable => 0,
},
post_date => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 0
is_nullable => 0,
});
__PACKAGE__->set_primary_key('post_id');
__PACKAGE__->belongs_to(
user_id =>
'CharmBoard::Schema::Result::Users',
'user_id'
);
__PACKAGE__->belongs_to(
thread_id =>
'CharmBoard::Schema::Result::Threads',
'thread_id'
);
1

View File

@ -1,5 +1,5 @@
package CharmBoard::Schema::Result::Session;
use base qw/DBIx::Class::Core/;
use base qw(DBIx::Class::Core);
__PACKAGE__->table('session');
__PACKAGE__->add_columns(
@ -9,12 +9,17 @@ __PACKAGE__->add_columns(
},
session_id => {
data_type => 'text',
is_nullable => 0
is_nullable => 0,
},
session_expiry => {
data_type => 'integer',
is_nullable => 0
is_nullable => 0,
});
__PACKAGE__->set_primary_key('user_id');
__PACKAGE__->belongs_to(
user_id =>
'CharmBoard::Schema::Result::Users',
'user_id'
);
1

View File

@ -0,0 +1,30 @@
package CharmBoard::Schema::Result::Subforums;
use base qw(DBIx::Class::Core);
__PACKAGE__->table('subforums');
__PACKAGE__->add_columns(
subf_id => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 0,
},
subf_cat => {
data_type => 'integer',
is_nullable => 0,
},
subf_name => {
data_type => 'text',
is_nullable => 0,
},
subf_desc => {
data_type => 'text',
is_nullable => 1,
});
__PACKAGE__->set_primary_key('subf_id');
__PACKAGE__->belongs_to(
subf_cat =>
'CharmBoard::Schema::Result::Categories',
{'foreign.cat_id' => 'self.subf_cat'}
);
1

View File

@ -1,21 +1,26 @@
package CharmBoard::Schema::Result::Threads;
use base qw/DBIx::Class::Core/;
use base qw(DBIx::Class::Core);
__PACKAGE__->table('threads');
__PACKAGE__->add_columns(
thread_id => {
thread_id => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 0
is_nullable => 0,
},
thread_title => {
thread_title => {
data_type => 'text',
is_nullable => 0
is_nullable => 0,
},
thread_cat => {
thread_subf => {
data_type => 'integer',
is_nullable => 1
is_nullable => 1,
});
__PACKAGE__->set_primary_key('thread_id');
__PACKAGE__->belongs_to(
thread_subf =>
'CharmBoard::Schema::Result::Subforums',
{'foreign.subf_id' => 'self.thread_subf'}
);
1

View File

@ -1,5 +1,5 @@
package CharmBoard::Schema::Result::User;
use base qw/DBIx::Class::Core/;
package CharmBoard::Schema::Result::Users;
use base qw(DBIx::Class::Core);
__PACKAGE__->table('users');
__PACKAGE__->add_columns(