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:
parent
744c916fde
commit
2ad959ffa8
15
database.sql
15
database.sql
|
@ -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
|
-- Text encoding used: UTF-8
|
||||||
--
|
--
|
||||||
|
@ -8,12 +8,7 @@ BEGIN TRANSACTION;
|
||||||
|
|
||||||
-- Table: categories
|
-- Table: categories
|
||||||
DROP TABLE IF EXISTS categories;
|
DROP TABLE IF EXISTS categories;
|
||||||
CREATE TABLE IF NOT EXISTS "categories" (
|
CREATE TABLE IF NOT EXISTS categories (cat_id INTEGER NOT NULL UNIQUE, cat_name TEXT, PRIMARY KEY (cat_id AUTOINCREMENT));
|
||||||
"cat_id" INTEGER NOT NULL UNIQUE,
|
|
||||||
"cat_name" TEXT,
|
|
||||||
"cat_desc" TEXT,
|
|
||||||
PRIMARY KEY("cat_id" AUTOINCREMENT)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Table: posts
|
-- Table: posts
|
||||||
DROP TABLE IF EXISTS posts;
|
DROP TABLE IF EXISTS posts;
|
||||||
|
@ -36,9 +31,13 @@ CREATE TABLE IF NOT EXISTS "session" (
|
||||||
PRIMARY KEY("user_id")
|
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
|
-- Table: threads
|
||||||
DROP TABLE IF EXISTS 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
|
-- Table: users
|
||||||
DROP TABLE IF EXISTS users;
|
DROP TABLE IF EXISTS users;
|
||||||
|
|
|
@ -32,8 +32,8 @@ sub registration_do ($app) {
|
||||||
|
|
||||||
# check to make sure username and/or email isn't already in use;
|
# check to make sure username and/or email isn't already in use;
|
||||||
# if not, continue with registration
|
# if not, continue with registration
|
||||||
my $userCheck = $app->schema->resultset('User')->search({username => $username})->single;
|
my $userCheck = $app->schema->resultset('Users')->search({username => $username})->single;
|
||||||
my $emailCheck = $app->schema->resultset('User')->search({email => $email})->single;
|
my $emailCheck = $app->schema->resultset('Users')->search({email => $email})->single;
|
||||||
if ( $userCheck || $emailCheck ) {
|
if ( $userCheck || $emailCheck ) {
|
||||||
if ( $userCheck && $emailCheck ) {
|
if ( $userCheck && $emailCheck ) {
|
||||||
# notify user that username and email are both already being used
|
# notify user that username and email are both already being used
|
||||||
|
@ -51,7 +51,7 @@ sub registration_do ($app) {
|
||||||
} else {
|
} else {
|
||||||
$password = $app->pepper . ':' . $password;
|
$password = $app->pepper . ':' . $password;
|
||||||
my ($hash, $salt) = pass_gen($password);
|
my ($hash, $salt) = pass_gen($password);
|
||||||
$app->schema->resultset('User')->create({
|
$app->schema->resultset('Users')->create({
|
||||||
username => $username,
|
username => $username,
|
||||||
email => $email,
|
email => $email,
|
||||||
password => $hash,
|
password => $hash,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use Authen::Passphrase::Argon2;
|
||||||
|
|
||||||
use Exporter qw(import);
|
use Exporter qw(import);
|
||||||
|
|
||||||
our @EXPORT = qw/ pass_gen /;
|
our @EXPORT = qw(pass_gen);
|
||||||
|
|
||||||
sub pass_gen ($) {
|
sub pass_gen ($) {
|
||||||
my $argon2 = Authen::Passphrase::Argon2->new(
|
my $argon2 = Authen::Passphrase::Argon2->new(
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
package CharmBoard::Schema::Result::Categories;
|
package CharmBoard::Schema::Result::Categories;
|
||||||
use base qw/DBIx::Class::Core/;
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('categories');
|
__PACKAGE__->table('categories');
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
||||||
cat_id => {
|
cat_id => {
|
||||||
data_type => 'integer',
|
data_type => 'integer',
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 1
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
cat_name => {
|
cat_name => {
|
||||||
data_type => 'text',
|
data_type => 'text',
|
||||||
is_nullable => 0
|
is_nullable => 0,
|
||||||
},
|
|
||||||
cat_desc => {
|
|
||||||
data_type => 'text',
|
|
||||||
is_nullable => 1
|
|
||||||
});
|
});
|
||||||
__PACKAGE__->set_primary_key('cat_id');
|
__PACKAGE__->set_primary_key('cat_id');
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,38 @@
|
||||||
package CharmBoard::Schema::Result::Posts;
|
package CharmBoard::Schema::Result::Posts;
|
||||||
use base qw/DBIx::Class::Core/;
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('posts');
|
__PACKAGE__->table('posts');
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
||||||
post_id => {
|
post_id => {
|
||||||
data_type => 'integer',
|
data_type => 'integer',
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
user_id => {
|
user_id => {
|
||||||
data_type => 'integer',
|
data_type => 'integer',
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
thread_id => {
|
thread_id => {
|
||||||
data_type => 'integer',
|
data_type => 'integer',
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
post_date => {
|
post_date => {
|
||||||
data_type => 'integer',
|
data_type => 'integer',
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0
|
is_nullable => 0,
|
||||||
});
|
});
|
||||||
__PACKAGE__->set_primary_key('post_id');
|
__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
|
1
|
|
@ -1,5 +1,5 @@
|
||||||
package CharmBoard::Schema::Result::Session;
|
package CharmBoard::Schema::Result::Session;
|
||||||
use base qw/DBIx::Class::Core/;
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('session');
|
__PACKAGE__->table('session');
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
||||||
|
@ -9,12 +9,17 @@ __PACKAGE__->add_columns(
|
||||||
},
|
},
|
||||||
session_id => {
|
session_id => {
|
||||||
data_type => 'text',
|
data_type => 'text',
|
||||||
is_nullable => 0
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
session_expiry => {
|
session_expiry => {
|
||||||
data_type => 'integer',
|
data_type => 'integer',
|
||||||
is_nullable => 0
|
is_nullable => 0,
|
||||||
});
|
});
|
||||||
__PACKAGE__->set_primary_key('user_id');
|
__PACKAGE__->set_primary_key('user_id');
|
||||||
|
__PACKAGE__->belongs_to(
|
||||||
|
user_id =>
|
||||||
|
'CharmBoard::Schema::Result::Users',
|
||||||
|
'user_id'
|
||||||
|
);
|
||||||
|
|
||||||
1
|
1
|
|
@ -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
|
|
@ -1,21 +1,26 @@
|
||||||
package CharmBoard::Schema::Result::Threads;
|
package CharmBoard::Schema::Result::Threads;
|
||||||
use base qw/DBIx::Class::Core/;
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('threads');
|
__PACKAGE__->table('threads');
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
||||||
thread_id => {
|
thread_id => {
|
||||||
data_type => 'integer',
|
data_type => 'integer',
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
thread_title => {
|
thread_title => {
|
||||||
data_type => 'text',
|
data_type => 'text',
|
||||||
is_nullable => 0
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
thread_cat => {
|
thread_subf => {
|
||||||
data_type => 'integer',
|
data_type => 'integer',
|
||||||
is_nullable => 1
|
is_nullable => 1,
|
||||||
});
|
});
|
||||||
__PACKAGE__->set_primary_key('thread_id');
|
__PACKAGE__->set_primary_key('thread_id');
|
||||||
|
__PACKAGE__->belongs_to(
|
||||||
|
thread_subf =>
|
||||||
|
'CharmBoard::Schema::Result::Subforums',
|
||||||
|
{'foreign.subf_id' => 'self.thread_subf'}
|
||||||
|
);
|
||||||
|
|
||||||
1
|
1
|
|
@ -1,5 +1,5 @@
|
||||||
package CharmBoard::Schema::Result::User;
|
package CharmBoard::Schema::Result::Users;
|
||||||
use base qw/DBIx::Class::Core/;
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('users');
|
__PACKAGE__->table('users');
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
Loading…
Reference in New Issue