-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.php
133 lines (111 loc) · 3.67 KB
/
seed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/** if abs path, die */
if (realpath(__FILE__) !== __FILE__) {
die('You are lost.');
}
$db = new SQLite3('db.sqlite');
/** remove all tables to start over */
// $db->exec('DROP TABLE IF EXISTS users');
// $db->exec('DROP TABLE IF EXISTS user_crops');
// $db->exec('DROP TABLE IF EXISTS states');
// $db->exec('DROP TABLE IF EXISTS crops');
// $db->exec('DROP TABLE IF EXISTS crops_states');
// $db->exec('DROP TABLE IF EXISTS crops_states_deadlines');
// $db->exec('DROP TABLE IF EXISTS deadlines_reminders');
/** create a users table: id, email, firstname, lastname, state, phone # */
$db->exec('CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
email TEXT NOT NULL,
firstname TEXT NOT NULL,
lastname TEXT NOT NULL,
state_id INTEGER,
phone TEXT,
password TEXT NOT NULL,
user_type TEXT NOT NULL,
allow_sms INTEGER NOT NULL DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)');
/** add the mobile_provider column to the users table if it doesn't exist */
$db->exec('ALTER TABLE users ADD COLUMN mobile_provider TEXT');
/** create user_crops table */
$db->exec('CREATE TABLE IF NOT EXISTS user_crops (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
crop_id INTEGER NOT NULL,
state_id INTEGER NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)');
/** create states table */
$db->exec('CREATE TABLE IF NOT EXISTS states (
id INTEGER PRIMARY KEY,
state TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)');
/** create crops table */
$db->exec('CREATE TABLE IF NOT EXISTS crops (
id INTEGER PRIMARY KEY,
crop TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)');
/** create crops_states_deadlines table */
$db->exec('CREATE TABLE IF NOT EXISTS crops_states_deadlines (
id INTEGER PRIMARY KEY,
crop_id INTEGER NOT NULL,
state_id INTEGER NOT NULL,
deadline_name TEXT NOT NULL,
deadline DATETIME NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)');
/** create deadlines_reminders table */
$db->exec('CREATE TABLE IF NOT EXISTS deadlines_reminders (
id INTEGER PRIMARY KEY,
deadline_id INTEGER NOT NULL,
reminder_send_time DATETIME NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)');
/** insert states (new england) */
// $db->exec('INSERT INTO states (state) VALUES ("Connecticut")');
// $db->exec('INSERT INTO states (state) VALUES ("Maine")');
// $db->exec('INSERT INTO states (state) VALUES ("Massachusetts")');
// $db->exec('INSERT INTO states (state) VALUES ("New Hampshire")');
// $db->exec('INSERT INTO states (state) VALUES ("Rhode Island")');
// $db->exec('INSERT INTO states (state) VALUES ("Vermont")');
/** insert crops */
$crops = [
"Apiculture",
"Apples",
"Barley",
"Blueberries-Lowbush",
"Clams",
"Controlled Environment",
"Corn",
"Cranberries",
"Dairy Revenue Prot.",
"Forage-Production",
"Forage Seeding",
"FM Sweet Corn",
"FM Tomatoes",
"Grapes",
"Livestock Gross Margin",
"Livestock Risk Protection",
"Micro Farm - Early Filer",
"Micro Farm - Late Filer",
"Nursery(Field Gr.& Cont.)",
"Pasture Rangeland Forage",
"Peaches",
"Potatoes",
"Oysters (Shellfish)",
"Soybeans",
"Tobacco - Cigar Binder",
"Tobacco - Cigar Wrapper",
"Whole Farm Rev Prot.-Early Filer",
"Whole Farm Rev Prot.-Late Filer",
"Wheat"
];
// foreach ($crops as $crop) {
// $db->exec('INSERT INTO crops (crop) VALUES ("' . $crop . '")');
// }
/** insert crops_states_deadlines */
/** apiculture, ct, sales_closing: 12/1/2023 */
/** apiculture, ct, acreage_reporting: 12/1/2023 */
/** apiculture, ct, production_reporting: 12/1/2023 */