Skip to content

Commit 679ca55

Browse files
YuvalYuval
authored andcommitted
refactor(sql): add missing GO statements for table definitions and indexes
1 parent 4533f6a commit 679ca55

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

01-Database/GroundShareDB.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ CREATE TABLE city (
2828
City_Name NVARCHAR(255) NOT NULL CHECK (LEN(TRIM(City_Name)) > 0),
2929
District NVARCHAR(255)
3030
);
31+
GO
3132

3233
CREATE TABLE event_type (
3334
EventType_ID INT IDENTITY(1,1) PRIMARY KEY,
3435
Name NVARCHAR(255) NOT NULL UNIQUE CHECK (LEN(TRIM(Name)) > 0)
3536
);
37+
GO
3638

3739
-- ============================================================
3840
-- 2. Streets (depends on city)
@@ -44,6 +46,7 @@ CREATE TABLE streets (
4446
Street_Name NVARCHAR(255) NOT NULL CHECK (LEN(TRIM(Street_Name)) > 0),
4547
UNIQUE (City_ID, Street_Name)
4648
);
49+
GO
4750

4851
-- ============================================================
4952
-- 3. Location (depends on city, streets)
@@ -59,8 +62,10 @@ CREATE TABLE location (
5962
Latitude FLOAT,
6063
Longitude FLOAT
6164
);
65+
GO
6266

6367
CREATE INDEX IX_location_geo ON location(Latitude, Longitude) WHERE Latitude IS NOT NULL;
68+
GO
6469

6570
-- ============================================================
6671
-- 4. Users (depends on location)
@@ -82,6 +87,7 @@ CREATE TABLE [user] (
8287
Created_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME(),
8388
Is_Active BIT NOT NULL DEFAULT 1
8489
);
90+
GO
8591

8692
-- ============================================================
8793
-- 5. Refresh tokens (for JWT rotation)
@@ -95,8 +101,10 @@ CREATE TABLE refresh_token (
95101
Created_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME(),
96102
Revoked_At DATETIME2
97103
);
104+
GO
98105

99106
CREATE INDEX IX_refresh_token_user ON refresh_token(User_ID);
107+
GO
100108

101109
-- ============================================================
102110
-- 6. Events / Reports (depends on location, event_type, user)
@@ -116,9 +124,12 @@ CREATE TABLE event (
116124
Created_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME(),
117125
CHECK (End_Date IS NULL OR End_Date >= Start_Date)
118126
);
127+
GO
119128

120129
CREATE INDEX IX_event_location ON event(Location_ID);
130+
GO
121131
CREATE INDEX IX_event_user ON event(User_ID);
132+
GO
122133

123134
-- ============================================================
124135
-- 7. Event votes (relevancy — like Waze)
@@ -131,6 +142,7 @@ CREATE TABLE event_vote (
131142
Voted_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME(),
132143
PRIMARY KEY (User_ID, Event_ID)
133144
);
145+
GO
134146

135147
-- ============================================================
136148
-- 8. Comments on events
@@ -144,8 +156,10 @@ CREATE TABLE comment (
144156
Picture NVARCHAR(MAX),
145157
Created_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME()
146158
);
159+
GO
147160

148161
CREATE INDEX IX_comment_event ON comment(Event_ID);
162+
GO
149163

150164
-- ============================================================
151165
-- 9. Reviews (on locations, with good/bad sentiment)
@@ -161,9 +175,12 @@ CREATE TABLE user_review (
161175
Picture NVARCHAR(MAX),
162176
Created_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME()
163177
);
178+
GO
164179

165180
CREATE INDEX IX_review_location ON user_review(Location_ID);
181+
GO
166182
CREATE UNIQUE INDEX UQ_review_user_location ON user_review(User_ID, Location_ID);
183+
GO
167184

168185
-- ============================================================
169186
-- 10. Favorites
@@ -175,6 +192,7 @@ CREATE TABLE add_to_favorites (
175192
Added_Date DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME(),
176193
PRIMARY KEY (User_ID, Location_ID)
177194
);
195+
GO
178196

179197
-- ============================================================
180198
-- 11. Plan status (building permits)
@@ -191,6 +209,7 @@ CREATE TABLE PlanStatus (
191209
Current_Stage NVARCHAR(255) DEFAULT N'Initiated',
192210
CHECK (End_Date IS NULL OR End_Date >= Start_Date)
193211
);
212+
GO
194213

195214
-- ============================================================
196215
-- 12. Comparison history
@@ -201,6 +220,7 @@ CREATE TABLE comparison (
201220
User_ID INT NOT NULL REFERENCES [user](User_ID),
202221
Created_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME()
203222
);
223+
GO
204224

205225
CREATE TABLE comparison_address (
206226
Comparison_ID INT NOT NULL REFERENCES comparison(Comparison_ID),
@@ -210,6 +230,7 @@ CREATE TABLE comparison_address (
210230
Address NVARCHAR(500),
211231
PRIMARY KEY (Comparison_ID, Location_ID)
212232
);
233+
GO
213234

214235
-- ============================================================
215236
-- 13. Survey / onboarding answers
@@ -232,6 +253,7 @@ CREATE TABLE survey (
232253
Is_GovRepresentative BIT NOT NULL DEFAULT 0, -- אני נציג/ת רשות / עובד/ת עירייה
233254
Created_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME()
234255
);
256+
GO
235257

236258
-- ============================================================
237259
-- 14. User activity log (for gamification feed)
@@ -245,8 +267,10 @@ CREATE TABLE user_activity (
245267
XP_Earned INT NOT NULL DEFAULT 0,
246268
Created_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME()
247269
);
270+
GO
248271

249272
CREATE INDEX IX_activity_user ON user_activity(User_ID, Created_At DESC);
273+
GO
250274

251275
-- ============================================================
252276
-- 15. Notification subscriptions (bell toggle per location)
@@ -258,6 +282,7 @@ CREATE TABLE notification_subscription (
258282
Created_At DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME(),
259283
PRIMARY KEY (User_ID, Location_ID)
260284
);
285+
GO
261286

262287
-- ============================================================
263288
-- Seed event types

0 commit comments

Comments
 (0)