Fix: Add missing state_name and country_name columns to SQL Server CREATE TABLE schemas#1351
Draft
Fix: Add missing state_name and country_name columns to SQL Server CREATE TABLE schemas#1351
Conversation
…er export schema Co-authored-by: dr5hn <6929121+dr5hn@users.noreply.github.com>
…EATE TABLE schemas Co-authored-by: dr5hn <6929121+dr5hn@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix missing columns in cities create table statement
Fix: Add missing state_name and country_name columns to SQL Server CREATE TABLE schemas
Feb 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SQL Server
CREATE TABLEstatements forcitiesandstateswere missing columns already present in the exported JSON data.What changed?
country_name NVARCHAR(255) NOT NULLaftercountry_codein thestatesschemastate_name NVARCHAR(255) NOT NULLafterstate_codein thecitiesschemacountry_name NVARCHAR(255) NOT NULLaftercountry_codein thecitiesschemaExportJson.phphas always exported these fields (state_name,country_namefor cities;country_namefor states), so the INSERT statements—which derive columns directly from JSON keys—will populate them correctly without further changes.Type of Change
Affected Locations
bin/Commands/ExportSqlServer.php—statesandcitiesschema definitionsChecklist
contributions/directoryidfield for new records (auto-assigned)Sources
Notes
The INSERT generation in
generateSqlServerInsert()derives column names fromarray_keys($data[0]), so no changes are needed there — once the schema includes the columns, the JSON-sourced data will fill them automatically.Original prompt
This section details on the original issue you should resolve
<issue_title>[Bug]: SQL Server States and Cities Create Table Statement has missing Columns:</issue_title>
<issue_description>### Issue Type
Incorrect Data (wrong information)
Location (if applicable)
No response
What's wrong?
SQL Server Create Table Statements:
/****** Object: Table [world].[cities] Script Date: 26/02/2026 11:46:11 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [world].[cities](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] nvarchar NOT NULL,
[state_id] [int] NOT NULL,
[state_code] nvarchar NOT NULL,
[state_name] nvarchar NOT NULL,
[country_id] [int] NOT NULL,
[country_code] nchar NOT NULL,
[country_name] nvarchar NOT NULL,
[latitude] [decimal](10, 8) NOT NULL,
[longitude] [decimal](11, 8) NOT NULL,
[native] nvarchar NULL,
[type] nvarchar NULL,
[level] [int] NULL,
[parent_id] [int] NULL,
[population] [bigint] NULL,
[timezone] nvarchar NULL,
[translations] nvarchar NULL,
[wikiDataId] nvarchar NULL,
[created_at] datetime2 NOT NULL,
[updated_at] datetime2 NOT NULL,
[flag] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [world].[cities] ADD DEFAULT (sysdatetime()) FOR [created_at]
GO
ALTER TABLE [world].[cities] ADD DEFAULT (sysdatetime()) FOR [updated_at]
GO
ALTER TABLE [world].[cities] ADD DEFAULT ((1)) FOR [flag]
GO
ALTER TABLE [world].[cities] WITH CHECK ADD CONSTRAINT [FK_cities_countries] FOREIGN KEY([country_id])
REFERENCES [world].[countries] ([id])
GO
ALTER TABLE [world].[cities] CHECK CONSTRAINT [FK_cities_countries]
GO
ALTER TABLE [world].[cities] WITH CHECK ADD CONSTRAINT [FK_cities_states] FOREIGN KEY([state_id])
REFERENCES [world].[states] ([id])
GO
ALTER TABLE [world].[cities] CHECK CONSTRAINT [FK_cities_states]
GO
/States Table/
/****** Object: Table [world].[states] Script Date: 26/02/2026 11:47:12 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [world].[states](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] nvarchar NOT NULL,
[country_id] [int] NOT NULL,
[country_code] nchar NOT NULL,
[country_name] nvarchar NOT NULL,
[fips_code] nvarchar NULL,
[iso2] nvarchar NULL,
[iso3166_2] nvarchar NULL,
[type] nvarchar NULL,
[level] [int] NULL,
[parent_id] [int] NULL,
[native] nvarchar NULL,
[latitude] [decimal](10, 8) NULL,
[longitude] [decimal](11, 8) NULL,
[timezone] nvarchar NULL,
[translations] nvarchar NULL,
[wikiDataId] nvarchar NULL,
[population] [bigint] NULL,
[created_at] datetime2 NULL,
[updated_at] datetime2 NOT NULL,
[flag] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [world].[states] ADD DEFAULT (sysdatetime()) FOR [created_at]
GO
ALTER TABLE [world].[states] ADD DEFAULT (sysdatetime()) FOR [updated_at]
GO
ALTER TABLE [world].[states] ADD DEFAULT ((1)) FOR [flag]
GO
ALTER TABLE [world].[states] WITH CHECK ADD CONSTRAINT [FK_states_countries] FOREIGN KEY([country_id])
REFERENCES [world].[countries] ([id])
GO
ALTER TABLE [world].[states] CHECK CONSTRAINT [FK_states_countries]
GO
What should it be?
Updated Create Table Statements:
/****** Object: Table [world].[cities] Script Date: 26/02/2026 11:46:11 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [world].[cities](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] nvarchar NOT NULL,
[state_id] [int] NOT NULL,
[state_code] nvarchar NOT NULL,
[state_name] nvarchar NOT NULL,
[country_id] [int] NOT NULL,
[country_code] nchar NOT NULL,
[country_name] nvarchar NOT NULL,
[latitude] [decimal](10, 8) NOT NULL,
[longitude] [decimal](11, 8) NOT NULL,
[native] nvarchar NULL,
[type] nvarchar NULL,
[level] [int] NULL,
[parent_id] [int] NULL,
[population] [bigint] NULL,
[timezone] nvarchar NULL,
[translations] nvarchar NULL,
[wikiDataId] nvarchar NULL,
[created_at] datetime2 NOT NULL,
[updated_at] datetime2 NOT NULL,
[flag] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [world].[cities] ADD DEFAULT (sysdatetime()) FOR [created_at]
GO
ALTER TABLE [world].[cities] A...
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.