Skip to content
Snippets Groups Projects
Select Git revision
  • 74d351e9cd953dee861ff57a8d2bfc91c2dc02d1
  • main default protected
  • rewrite
  • production
4 results

admin_initdatabase.php

Blame
  • admin_initdatabase.php 5.39 KiB
    <?php 
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        if ($_POST['init'] == 'Init') {
            echo("<p>Initialising DB...");
            echo "<p>Create table `accounts`";
            $stmt = $pdo->prepare('create table accounts
    (
        id           varchar(7)                             not null
            primary key,
        email        text                                   not null,
        created_date datetime default current_timestamp()   not null,
        display_name text                                   null,
        password     text                                   not null,
        verified     tinyint(1) default 0                   not null,
        has_pfp      tinyint(1) default 0                   not null,
        is_admin     tinyint(1) default 0                   not null,
        constraint email
            unique (email) using hash
    );');
            
            try {
                $stmt->execute();
            } catch (PDOException $e) {
                echo('<p>An error occurred: '. $e->getMessage() .'. Will skip. (Most likely the table already exists.)');
            }
    
            echo '<p>Create the `password_resets` table';
            $stmt = $pdo->prepare('create table password_resets
    (
        id         int auto_increment
            primary key,
        auth_id    tinytext   not null,
        owner_id   varchar(7) not null,
        expiration int        not null,
        constraint password_resets_ibfk_1
            foreign key (owner_id) references accounts (id)
    );');
    
            try {
                $stmt->execute();
            } catch (PDOException $e) {
                echo('<p>An error occurred: '. $e->getMessage() .'. Most likely this is already set.');
            }
    
            echo '<p>Create the `apps` table';
    
            try {
                db_execute('create table apps (
                id int auto_increment
                        primary key,
                owner_id    varchar(7)  not null,
                title       text        not null,
                description text,
                image       text    default "https://id.byecorps.com/assets/default.png"   not null,
                type        text    null,
                callback    text    null,
                constraint apps_ibfk_1 
                    foreign key (owner_id) references accounts (id)
                );');
            } catch (PDOException $e) {
                echo('<p>An error occurred: '. $e->getMessage() .'. Most likely this is already set.');
            }
    
    
            echo '<p>Create the `badges` table';
    
            try {
                db_execute('create table badges (
                id int auto_increment