Skip to content

Commit 587cb6e

Browse files
committed
feat(database): update database schema for new features
- Rename tables and columns to better reflect their content and usage - Add new columns for upcoming features like ad config and account action config - Remove unused columns to simplify the schema - Adjust foreign key relationships to match new table names """ Changed database schema to support new features and improve data organization. Here are the key changes: - Renamed 'app_config' to 'remote_config' to clarify its purpose - Renamed 'categories' to 'topics' to better reflect the content - Removed 'type' columns from multiple tables as they were no longer used - Added new columns to 'remote_config' for ad config, account action config, and app status - Changed 'categories' to 'topics' in the 'headlines' table - Removed 'last_engagement_shown_at' from 'users' table - Updated table and column names to align with new feature requirements
1 parent cdb98e0 commit 587cb6e

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lib/src/services/database_seeding_service.dart

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,35 @@ class DatabaseSeedingService {
3939
await _connection.execute('''
4040
CREATE TABLE IF NOT EXISTS users (
4141
id TEXT PRIMARY KEY,
42-
email TEXT UNIQUE,
43-
roles JSONB NOT NULL,
44-
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
45-
last_engagement_shown_at TIMESTAMPTZ
42+
email TEXT NOT NULL UNIQUE,
43+
app_role TEXT NOT NULL,
44+
dashboard_role TEXT NOT NULL,
45+
feed_action_status JSONB NOT NULL,
46+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
4647
);
4748
''');
4849

49-
_log.fine('Creating "app_config" table...');
50+
_log.fine('Creating "remote_config" table...');
5051
await _connection.execute('''
51-
CREATE TABLE IF NOT EXISTS app_config (
52+
CREATE TABLE IF NOT EXISTS remote_config (
5253
id TEXT PRIMARY KEY,
5354
user_preference_limits JSONB NOT NULL,
55+
ad_config JSONB NOT NULL,
56+
account_action_config JSONB NOT NULL,
57+
app_status JSONB NOT NULL,
5458
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
5559
updated_at TIMESTAMPTZ
5660
);
5761
''');
5862

59-
_log.fine('Creating "categories" table...');
63+
_log.fine('Creating "topics" table...');
6064
await _connection.execute('''
61-
CREATE TABLE IF NOT EXISTS categories (
65+
CREATE TABLE IF NOT EXISTS topics (
6266
id TEXT PRIMARY KEY,
6367
name TEXT NOT NULL,
6468
description TEXT,
6569
icon_url TEXT,
6670
status TEXT,
67-
type TEXT,
6871
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
6972
updated_at TIMESTAMPTZ
7073
);
@@ -79,7 +82,6 @@ class DatabaseSeedingService {
7982
url TEXT,
8083
language TEXT,
8184
status TEXT,
82-
type TEXT,
8385
source_type TEXT,
8486
headquarters_country_id TEXT REFERENCES countries(id),
8587
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
@@ -95,7 +97,6 @@ class DatabaseSeedingService {
9597
iso_code TEXT NOT NULL UNIQUE,
9698
flag_url TEXT NOT NULL,
9799
status TEXT,
98-
type TEXT,
99100
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
100101
updated_at TIMESTAMPTZ
101102
);
@@ -106,16 +107,15 @@ class DatabaseSeedingService {
106107
CREATE TABLE IF NOT EXISTS headlines (
107108
id TEXT PRIMARY KEY,
108109
title TEXT NOT NULL,
109-
source_id TEXT REFERENCES sources(id),
110-
category_id TEXT REFERENCES categories(id),
111-
image_url TEXT,
110+
excerpt TEXT,
112111
url TEXT,
113-
published_at TIMESTAMPTZ,
114-
description TEXT,
112+
image_url TEXT,
113+
source_id TEXT REFERENCES sources(id),
114+
topic_id TEXT REFERENCES topics(id),
115+
event_country_id TEXT REFERENCES countries(id),
115116
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
116117
updated_at TIMESTAMPTZ,
117118
status TEXT,
118-
type TEXT
119119
);
120120
''');
121121

@@ -127,8 +127,6 @@ class DatabaseSeedingService {
127127
display_settings JSONB NOT NULL, -- Nested object, stored as JSON
128128
language TEXT NOT NULL, -- Simple string, stored as TEXT
129129
feed_preferences JSONB NOT NULL,
130-
engagement_shown_counts JSONB NOT NULL,
131-
engagement_last_shown_timestamps JSONB NOT NULL,
132130
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
133131
updated_at TIMESTAMPTZ
134132
);
@@ -139,7 +137,7 @@ class DatabaseSeedingService {
139137
CREATE TABLE IF NOT EXISTS user_content_preferences (
140138
id TEXT PRIMARY KEY,
141139
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
142-
followed_categories JSONB NOT NULL,
140+
followed_topics JSONB NOT NULL,
143141
followed_sources JSONB NOT NULL,
144142
followed_countries JSONB NOT NULL,
145143
saved_headlines JSONB NOT NULL,

0 commit comments

Comments
 (0)